首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个测试程序,为什么老是报错呢?菜鸟,请前辈指点

2012-02-14 
一个测试程序,为什么老是报错呢?初学者,请前辈指点。#includeiostream.hclassotherclassbase_CWinApp{pu

一个测试程序,为什么老是报错呢?初学者,请前辈指点。
#include   <iostream.h>
class   other;
class   base_CWinApp
{
public:
other   other1;
base_CWinApp()
{
other1.pbase=this;
}
void   area()
{
cout < < "father   area " < <endl;
}

};
class   CtestApp:public   base_CWinApp
{
public:
void   area()
{
cout < < "son   area " < <endl;
}
};

class   other
{
public:
base_CWinApp   *pbase;
};

CtestApp   theApp;

void   main()
{
theApp.other1.pbase-> area();
}
我是想验证,this指针指向的是theApp,但总有三个错误,不知如何改正。初学者,请前辈指点。

[解决办法]
#include <iostream.h>

class base_CWinApp;

class other
{
public:
base_CWinApp *pbase;
};

class base_CWinApp
{
public:
other other1;
base_CWinApp()
{
other1.pbase=this;
}
void area()
{
cout < < "father area " < <endl;
}

};

class CtestApp:public base_CWinApp
{
public:
void area()
{
cout < < "son area " < <endl;
}
};


CtestApp theApp;

void main()
{
theApp.other1.pbase-> area();
}

[解决办法]
#include <iostream>

using namespace std;

class base_CWinApp;
class other
{
public:
base_CWinApp *pbase;
};


class base_CWinApp
{
public:
other other1;
base_CWinApp()
{
other1.pbase=this;
}
void area()
{
cout < < "father area " < <endl;
}

};
class CtestApp:public base_CWinApp
{
public:
void area()
{
cout < < "son area " < <endl;
}
};


CtestApp theApp;

int main()
{
theApp.other1.pbase-> area();

return 0;
}

热点排行