【发布时间】:2013-12-14 22:16:26
【问题描述】:
我编写了一个关于 const 类的非常简单的程序,但是,当我编译时,出现错误:void Test::printxy(void)' : cannot convert 'this' pointer from 'const Test' to 'Test & '
程序如下
#include <iostream>
using namespace std;
class Test
{
private:
int x, y;
public:
Test(int a = 1, int b = 1) : x(a), y(b) {};
void printxy();
};
void Test::printxy()
{
cout << "x*y=" << x*y << endl;
}
void main(void)
{
const Test t;
t.printxy();
system("pause");
}
【问题讨论】:
-
为什么这个网站有这么多问题都用
void main? -
@remyabel :我自己也想知道。甚至 Herbert Schildt 的书(至少我可以在 amazon.com 上看到的那部分)都说对了。