Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2342218
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:01:58

我现在学习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---------------------

阅读(1057) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~