我想超载引用操作,但在编译下面的代码导致错误'initializing' : cannot convert from 'X' to 'int'
:超载引用操作
struct X {
void f() {}
int operator*() const { return 5; }
};
int main()
{
X* x = new X;
int t = *x;
delete x;
return -898;
}
我在做什么错?
'运营商INT '有很多问题,最好避免。解引用运算符可以用作指针仿真。 – Potatoswatter 2010-03-24 07:59:40
@David:转换为'bool'的人比其他人多一个人,但也许这是一个下降; v) – Potatoswatter 2010-03-24 08:05:55
@David:问题是关于'int operator *',而不是'operator int *' – visitor 2010-03-24 12:10:57