标题:C++类的继承问题和类的构造函数继承问题
取消只看楼主
nuclear_1
Rank: 1
来 自:成都
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-10-6
结帖率:50%
已结贴  问题点数:10 回复次数:0 
C++类的继承问题和类的构造函数继承问题
楼主建了两个类,第二个类公有方式继承第一个类,这里类的构造函数继承有问题,还有字符串进行传递时应该怎么传递好呢?麻烦给位大侠看看楼主的代码问题出在哪里了!如果有改进后的程序,能解决字符串作为函数参数进行传递的问题就更好了!

#include<iostream.h>
class glass
{
private:
    int weight;
    int length;
    int width;
public:
    glass(int x,int y,int z)
        {
            weight=x;
            length=y;
            width=z;
        }
    display();
};
glass :: display()
{
    cout<<"The glass's weight:"<<weight<<",length:"<<length<<",width:"<<width<<endl;
}
class window : public glass
{
private:
    char color[10];
public:
    window (int x,int y,int z, char* c) : glass (int x,int y,int z)
        {
        color=c;
        }
    display();
};
window :: display()
{
    cout<<"The window's weight:"<<weight<<",length:"<<length<<",width:"<<width<<",color:"
    <<color<<endl;
}
int main()
{
    char color1[10]="yellow";
    char* color =color1;
glass number1(100,75,85);
window number2(99,74,84,color);
glass.display();
window.display();
return 0;
}














搜索更多相关主题的帖子: public include display private 
2013-06-05 21:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-414618-1-1.html




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

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