| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 777 人关注过本帖
标题:多重继承派生类
只看楼主 加入收藏
zhy0401052
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2009-7-19
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:2 
多重继承派生类
#include<iostream>
#include<string>
using namespace std;
class teacher
{public:
teacher(string nam,int a,string til):name(nam),age(a),title(til){}
void display()
{cout<<"name:"<<name<<endl;
cout<<"age:"<<age<<endl;
cout<<"title:"<<title<<endl;
}
protected:
    string name;
    int age;
    string title;
};
class student
{public:
student(string nam,int s1)
{strcpy(name1,nam);
score=s1;

}
void display1()
{cout<<"name:"<<name1<<endl;

cout<<"score:"<<score<<endl;
}
protected:
    string name1;
    int score;
};
class grade:public teacher,public student
{public(string nam,int a,string til,int s1,float w):teacher(nam,a,til),student(nam,s1),wage(w){}
void show()
{display();
display1();
cout<<"wage:"<<wage<<endl;
}
private:
    float wage;
};
int main()
{grade grad1("zhangfei",25,"assistant",89,10224);
grad1.show();
return 0;
}
哪位兄弟帮忙看下,这个程序调试时老是出现错误,谢谢了!
错误方式为
--------------------Configuration: paishenggouzhaohanshu - Win32 Debug--------------------
Compiling...
duochongjicheng.cpp
C:\Documents and Settings\Administrator\桌面\GGG\duochongjicheng.cpp(19) : error C2664: 'strcpy' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Documents and Settings\Administrator\桌面\GGG\duochongjicheng.cpp(34) : error C2320: expected ':' to follow access specifier '('
C:\Documents and Settings\Administrator\桌面\GGG\duochongjicheng.cpp(34) : error C2226: syntax error : unexpected type 'string'
C:\Documents and Settings\Administrator\桌面\GGG\duochongjicheng.cpp(34) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
C:\Documents and Settings\Administrator\桌面\GGG\duochongjicheng.cpp(44) : error C2660: 'grade::grade' : function does not take 5 parameters
Error executing cl.exe.

duochongjicheng.obj - 5 error(s), 0 warning(s)
搜索更多相关主题的帖子: 多重继承 
2009-08-14 13:14
xufen340
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:166
专家分:1351
注 册:2009-8-7
收藏
得分:20 
看strcpy的函数声明
char *strcpy(
   char *strDestination,
   const char *strSource  
);

strcpy第二个参数是常量,
而你strcpy(name1,nam);第二个参数是变量
2009-08-14 15:26
xufen340
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:166
专家分:1351
注 册:2009-8-7
收藏
得分:0 
脑子糊涂了,不好意思,说错了,是类型不匹配。
char *strcpy(  
   char *strDestination,  
   const char *strSource   
);  
第二个参数为
char*.
而你strcpy(name1,nam);
string nam;
你的第二个参数是string.
所以改成:char* nam;就可以
2009-08-15 09:23
快速回复:多重继承派生类
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016371 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved