主题:大家帮忙看下程序,一实现就报错,郁闷啊
#include<string>
#include<list>
#include<iostream>
using namespace std;
class Employee{
string first_name,family_name;
short department;
public:
Employee(const string& name,int dept);
virtual void print() const;
};
void Employee::print() const
{
cout<<family_name<<'\t'<<department<<'\n';
}
class Manager:public Employee{
list<Employee*> group;
short level;
public:
Manager(const string& name,int dept,int lvl);
void print() const;
};
void Manager::print() const
{
Employee::print();
cout<<"\tlevel"<<level<<'\n';
}
void print_list(const list<Employee*>&s)
{
for(list<Employee*>::const_iterator p=s.begin();p!=s.end();++p)
(*p)->print();
}
int main()
{
Employee e("Brown",1234);
// Manager m("Smith",1234,2);
// list<Employee*> empl;
// empl.push_front(&e);
// empl.push_front(&m);
// print_list(empl);
return 0;
}
在Employee e("Brown",1234);未申请前没报错
申请后就出错
--------------------Configuration: virfunc - Win32 Debug--------------------
Compiling...
virfunc.cpp
Linking...
virfunc.obj : error LNK2001: unresolved external symbol "public: __thiscall Employee::Employee(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (??0Employee@@QAE@ABV?$basic_string@DU?$char_traits@
D@std@@V?$allocator@D@2@@std@@H@Z)
Debug/virfunc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
#include<list>
#include<iostream>
using namespace std;
class Employee{
string first_name,family_name;
short department;
public:
Employee(const string& name,int dept);
virtual void print() const;
};
void Employee::print() const
{
cout<<family_name<<'\t'<<department<<'\n';
}
class Manager:public Employee{
list<Employee*> group;
short level;
public:
Manager(const string& name,int dept,int lvl);
void print() const;
};
void Manager::print() const
{
Employee::print();
cout<<"\tlevel"<<level<<'\n';
}
void print_list(const list<Employee*>&s)
{
for(list<Employee*>::const_iterator p=s.begin();p!=s.end();++p)
(*p)->print();
}
int main()
{
Employee e("Brown",1234);
// Manager m("Smith",1234,2);
// list<Employee*> empl;
// empl.push_front(&e);
// empl.push_front(&m);
// print_list(empl);
return 0;
}
在Employee e("Brown",1234);未申请前没报错
申请后就出错
--------------------Configuration: virfunc - Win32 Debug--------------------
Compiling...
virfunc.cpp
Linking...
virfunc.obj : error LNK2001: unresolved external symbol "public: __thiscall Employee::Employee(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (??0Employee@@QAE@ABV?$basic_string@DU?$char_traits@
D@std@@V?$allocator@D@2@@std@@H@Z)
Debug/virfunc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.