| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 582 人关注过本帖
标题:多层派生时的构造函数
只看楼主 加入收藏
harbincampus
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2006-12-11
收藏
 问题点数:0 回复次数:4 
多层派生时的构造函数

小弟这个程序是看的书本上的,用mingw编译就是不通过.
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(int n,string nam )
{
num=n;
name=nam;
}
void display()
{
cout<<"num: "<<num<<endl;
cout<<"name: "<<name<<endl;
}
protected:
int num;
string name;
};
class Student1:public Student
{
public:
Student1(int n,char nam[10],int a):Student(n,nam)
{
age=a;
}
void show()
{
display();
cout<<"age: "<<age<<endl;
}
private:
int age;
};
class Student2:public Student1
{
public:
Student2(int n,string nam,int a,int s):Student1(n,nam,a)
{
score=s;
}
void show_all()
{
show();
cout<<"score: "<<score<<endl;
}
private:
int score;
};

int main()
{
Student2 stud(10010,"li",17,89);
stud.show_all();

return 0;
}

搜索更多相关主题的帖子: 函数 构造 派生 
2006-12-12 00:12
song4
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:38
帖 子:1533
专家分:4
注 册:2006-3-25
收藏
得分:0 
VC6。0正常
你说一下,它说哪错了

嵌入式 ARM 单片机 驱动 RT操作系统 J2ME LINUX  Symbian C C++ 数据结构 JAVA Oracle 设计模式 软件工程 JSP
2006-12-12 09:45
harbincampus
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2006-12-11
收藏
得分:0 

Configuration: 4 - Debug--------------------
Compiling...
item.cpp
item.cpp: In constructor `Student2::Student2(int, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int, int)':
item.cpp:40: error: no matching function for call to `Student1::Student1(int&,
std::string&, int&)'
item.cpp:22: error: candidates are: Student1::Student1(const Student1&)
item.cpp:24: error: Student1::Student1(int, char*, int)
item.cpp:58:2: warning: no newline at end of file

item.o - 3 error(s), 1 warning(s)

麻烦老兄了,多谢

2006-12-12 10:07
song4
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:38
帖 子:1533
专家分:4
注 册:2006-3-25
收藏
得分:0 
Student1(int n,string nam[10],int a):Student(n,nam)
{
age=a;
}
这改一下试试

嵌入式 ARM 单片机 驱动 RT操作系统 J2ME LINUX  Symbian C C++ 数据结构 JAVA Oracle 设计模式 软件工程 JSP
2006-12-12 10:21
harbincampus
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2006-12-11
收藏
得分:0 

版主好厉害,改了之后果然能通过,但是想不通为什么.谢谢啦

2006-12-12 16:18
快速回复:多层派生时的构造函数
数据加载中...
 
   



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

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