一个测试程序,为什么老是报错呢?初学者,请前辈指点。
#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;
}