2 yr131 yr131 于 2015.06.15 22:48 提问

求大神帮我看看这段代码main函数里赋值有什么问题,新手没金币,抱歉!
c++
<textarea readonly="readonly" name="code" class="c++"> 
#include<iostream>
#include<string>
using namespace std;
class Teacher
{
public: 
    //Teacher(){}
    Teacher(string n, int a, string s, string ad, string c, string t);
    void display();
protected:
    string name;
    int age;
    string sex;
    string add;
    string call;
    string title;
};
class Cadre
{public:
    //Cadre(){}
    Cadre(string n, int a, string s, string ad,string c, string p);
    void display();
protected:
    string name;
    int age;
    string sex;
    string add;
    string call;
    string post;
};
class Teacher_Cadre:public Teacher,public Cadre  
{
public:
    //Teacher_Cadre(){}
    Teacher_Cadre(string n,int a,string s,string add,string c,string t,string p,double w):Teacher(n,a,s,add,c,t),Cadre(n,a,s,add,c,p),wages(w){} 
    void show();
protected:
    double wages;
};
void Teacher::display()    
{    
    cout<<"姓名: "<<name<<endl;    
    cout<<"年龄: "<<age<<endl;    
    cout<<"性别: "<<sex<<endl;    
    cout<<"地址: "<<add<<endl;    
    cout<<"电话: "<<call<<endl;    
    cout<<"职称: "<<title<<endl;    
}    
void Cadre::display()    
{    
    cout<<"姓名: "<<name<<endl;    
    cout<<"年龄: "<<age<<endl;    
    cout<<"性别: "<<sex<<endl;    
    cout<<"地址: "<<add<<endl;    
    cout<<"电话: "<<call<<endl;    
    cout<<"职务: "<<post<<endl;   
}    
void Teacher_Cadre::show()  //在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数  
{    
    Teacher::display();    
    cout<<"职务: "<<Cadre::post<<endl;  //指定作用域  
    cout<<"工资: "<<wages<<endl; 
}
Teacher::Teacher(string n,int a,string s,string ad,string c,string t)    
{    
    name=n;    
    age=a;    
    sex=s;     
    add=ad;    
    call=c;    
    title=t;    
}      
Cadre::Cadre(string n,int a,string s,string ad,string c,string p)    
{
    name=n;    
    age=a;    
    sex=s;     
    add=ad;    
    call=c;    
    post=p;    
}  
/*Teacher_Cadre::Teacher_Cadre(string n,int a,char s,string add,string c,string t,string p,double w=0):Teacher(n,a,s,add,c,t),Cadre(n,a,s,add,c,p)   
{    
    wages=w;    
}*/
#include"Teacher&Cadre.h"
int main()
{
    Teacher_Cadre tc[3]={
        {"zhang",20,"male","Build 305-503","6081202","tuyor","staff",8000},
        {"chen",38,"male","Build 3A-302","6088132","associate professor","subdecanal",20000},
        {"fan",30,"female","Build 2A-202","6088099","lectuer","staff room director",15000}};
    for(int i;i<3;i++)
        tc[i].show();
    return 0;
}</textarea>

6个回答

oyljerry
oyljerry   Ds   Rxr 2015.06.15 23:03

需要c ++11语法支持。

caozhy
caozhy   Ds   Rxr 2015.06.15 23:33

8000
->
8000f
或8000.0
别的类似
include"Teacher&Cadre.h"
头文件最好不要and符号

caozhy
caozhy   Ds   Rxr 2015.06.15 23:34

另外需要VC++ 2012 2013才能支持集合初始化器。

gamefinity
gamefinity   Rxr 2015.06.16 05:49

main里面

for(int i;i<3;i++)

应该是

for(int i=0;i<3;i++)
frank_20080215
frank_20080215   2015.06.16 07:19

双重继承造成的困惑。继承的两个父类之字段都是一样的。子类判断使用哪个父类的字段出现了歧义。

beacon_2011
beacon_2011   Rxr 2015.06.16 14:07

需要VC++ 2011以上版本吧

Csdn user default icon
上传中...
上传图片
插入图片