[問題] 我怎麼看都不知道問題出在哪阿!!
不好意思 我是位新手
在寫作業中遇到很無法理解的問題
所以想請教各位
主題是一個能夠print出員工的first name, last name以及salary
且要用到class的概念
以下是標頭檔:
#include<string>
using std::string;
class Employee
{
public:
Employee(string, string, int);
void setFirstName(string);
string getFirstName();
void setLastName(string);
string getLastName();
void setSalary(int);
int getSalary();
void displayFirstname();
void displayLastname();
void displaySalarynumber();
private:
string firstName;
string lastName;
int salary;
};
建構檔:
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<string>
using std::string;
using std::getline;
#include"Employee.h"
Employee::Employee(string name )
{
setFirstName(name);
}
void Employee::setFirstName(string name)
{
firstName=name;
}
string Employee::getFirstName()
{
return firstName;
}
void displayFirstName()
{
cout<<"the employee's firstname is:"<<getFirstName()<<endl;
}
Employee::Employee(string name1 )
{
setLastName(name1);
}
void Employee::setLastName(string name1)
{
lastName=name1;
}
string Employee::getLastName()
{
return lastName;
}
void diplayLastName()
{
cout<<"the employee's lastname is:"<<getLastName()<<endl;
}
Employee::Employee(int number)
{
setSalary(number);
}
void Employee::setSalary(int number)
{
salary=number;
}
int Employee::getSalary()
{
return salary;
}
void displaySalarynumber()
{
cout<<"the employee's salary is"<<getSalary()<<endl;
}
main:
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include"Employee.h"
int main()
{
Employee myEmployee(" worker's profile!");
myEmployee.displayFirstname();
myEmployee.displayLastname();
myEmployee.displaySalarynumber();
system("pause");
return 0;
}
debug:
1>.\workers.cpp(14) : error C2511: 'Employee::Employee(std::string)' : overloaded
member function not found in 'Employee'
1> c:\documents and settings\wupeiing\my documents\visual studio 2005\
projects\working\working\Employee.h(5) : see declaration of 'Employee'
1>.\workers.cpp(27) : error C3861: 'getFirstName': identifier not found
1>.\workers.cpp(30) : error C2511: 'Employee::Employee(std::string)' : overloaded
member function not found in 'Employee'
1> c:\documents and settings\wupeiing\my documents\visual studio 2005
\projects\working\working\Employee.h(5) : see declaration of 'Employee'
1>.\workers.cpp(43) : error C3861: 'getLastName': identifier not found
1>.\workers.cpp(46) : error C2511: 'Employee::Employee(int)' : overloaded
member function not found in 'Employee'
1> c:\documents and settings\wupeiing\my documents\visual studio 2005
\projects\working\working\Employee.h(5) : see declaration of 'Employee'
1>.\workers.cpp(60) : error C3861: 'getSalary': identifier not found
1>main.cpp
1>.\main.cpp(12) : error C2664: 'Employee::Employee(const Employee &)' :
cannot convert parameter 1 from 'const char [20]' to 'const Employee &'
1> Reason: cannot convert from 'const char [20]' to 'const Employee'
1> No constructor could take the source type, or constructor overload
resolution was ambiguous
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\Wupeiing\My Documents\
Visual Studio 2005\Projects\working\working\Debug\BuildLog.htm"
這困擾了我好一陣子了 拜託各位神人了 謝謝!!
我到底是哪裡沒有define清楚呢??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.71.1.186
推
12/13 15:39, , 1F
12/13 15:39, 1F
→
12/13 15:39, , 2F
12/13 15:39, 2F
推
12/13 15:42, , 3F
12/13 15:42, 3F
→
12/13 15:45, , 4F
12/13 15:45, 4F
→
12/13 15:45, , 5F
12/13 15:45, 5F
→
12/13 15:47, , 6F
12/13 15:47, 6F
→
12/13 17:11, , 7F
12/13 17:11, 7F
→
12/13 17:12, , 8F
12/13 17:12, 8F
→
12/13 18:05, , 9F
12/13 18:05, 9F
→
12/13 18:08, , 10F
12/13 18:08, 10F
→
12/13 18:08, , 11F
12/13 18:08, 11F
→
12/13 18:09, , 12F
12/13 18:09, 12F
噓
12/14 12:45, , 13F
12/14 12:45, 13F