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;
}