我现在学习c++,可是当我找书上的算法在机子上运行时,却不行。
异构数组,代码如下:
#include
class house
{ private:
string id;
public:
house(void)
{id="house";
}
virtual void paint(void)
{cout< };
class woodframehouse:public house1
{private:
string id;
public:
woodframehouse(void):house()
{id="wood frame";}
virtual void paint(void)
{cout<<"painting a"< house1::paint();
}
};
class stuccohouse:public house1
{private:
string id;
public:
tuccohouse(void):house()
{id="stucco house";}
virtual void paint(void)
{cout<<"painting a"< house1::paint();
}
};
class vinyilsidedhouse::public house1
{private:
string id;
public:
vinyilsidedhouse(void):house()
{id="vinyl sided";}
virtual void paint(void)
{cout<<"painting a"< house1::paint();
}
};
为什么,老说类的声明语法错误啊。
不知道那位大虾不吝赐教,小弟感激不尽。
--------------------next---------------------
//是不是应该这样啊
#include
#include
using namespace std;
class house
{
private:
string id;
public:
house(void)
{
id="house";
}
virtual void paint(void)
{
cout< }
};
class woodframehouse:public house
{
private:
string id;
public:
woodframehouse(void):house()
{
id="wood frame";
}
virtual void paint(void)
{
cout<<"painting a"< house::paint();
}
};
class stuccohouse:public house
{
private:
string id;
public:
stuccohouse(void):house()
{
id="stucco house";
}
virtual void paint(void)
{
cout<<"painting a"< house::paint();
}
};
class vinyilsidedhouse:public house
{
private:
string id;
public:
vinyilsidedhouse(void):house()
{
id="vinyl sided";
}
virtual void paint(void)
{
cout<<"painting a"< house::paint();
}
};
int main(int argc, char* argv[])
{
woodframehouse h1;
stuccohouse h2;
vinyilsidedhouse h3;
house *h[3]={&h1,&h2,&h3};
for(int i=0; i<3; i++)
h[i]->paint();
return 0;
}
--------------------next---------------------
阅读(1061) | 评论(0) | 转发(0) |