虚基类构造函数的问题
/*设计一个虚基类base,包含name和私有数据成员以及相关的成员函数,由它派生出领导类leader,包含职务和部门私有数据成员以及相关的成员函数(自定义)。
再由base派 生出工程师类engineer,包含职称和专业私有数据成员以及相关的成员函数(自定义)。
然后由leader和engineer类派生出主任工程师类chairman。
采用一些数据进行测试,注意构造函数调用的先后顺序。*/
#include <iostream>
#include <string>
using namespace std;
class Base
{
public:
Base(string na):name(na)
{
cout<<"Constructing Base"<<endl;
}//构造函数
Base();
string getN() const
{
return name;
}
void showBase()
{
cout<<"Name:"<<name<<endl;
}
private:
string name;
};
class Leader:virtual public Base
{
public:
/*Leader(string na,string nj,string nd):Base(na),jobs(nj),department(nd)
{
cout<<"Constructing Leader"<<endl;
}//构造函数*///参数不符合问题
Leader(string nj,string nd):Base(),jobs(nj),department(nd)
{
cout<<"Constructing Leader"<<endl;
}
string getJ() const
{
return jobs;
}
string getD() const
{
return department;
}
void showLeader()
{
cout<<"Jobs:"<<jobs<<endl<<"Department:"<<department<<endl;
}
private:
string jobs;
string department;
};
class Engineer:virtual public Base
{
public:
/*Engineer(string na,string nk,string nm):Base(na),nick(nk),major(nm)
{
cout<<"Constructing Engineer"<<endl;
}//构造函数*/
Engineer(string nk,string nm):Base(),nick(nk),major(nm)
{
cout<<"Constructing Engineer"<<endl;
}
string getK() const
{
return nick;
}
string getM() const
{
return major;
}
void showEngineer()
{
cout<<"Nickname:"<<nick<<endl<<"Major:"<<major<<endl;
}
private:
string nick;
string major;
};
class Chairman:public Leader,public Engineer
{
public:
Chairman(string na2,string nj,string nd,string nk,string nm,int ne):Base(na2),Leader(nj,nd),Engineer(nk,nm),age(ne)
{
cout<<"Constructing Chairman"<<endl;
}//构造函数
int getE() const
{
return age;
}
void showChairman()
{
cout<<"Age:"<<age<<endl;
}
private:
int age;
};
int main()
{
Chairman myp("Ben","journalist","economic","manager","writing",28);
myp.showBase();
myp.showLeader();
myp.showEngineer();
myp.showChairman();
return 0;
}
在devC++能正常运行,但是在vc++链接时出错,请大家帮忙看看这个程序有错吗?
还有被注释掉的构造函数错在哪里?