64,654
社区成员
发帖
与我相关
我的任务
分享
class Test
{
public:
Test()
{
m_a = 10;
}
~Test()
{
}
bool operator !()
{
return true;
}
private:
int m_a;
};
int main()
{
Test t;
if(!t)
{
cout << "!t" << endl;
}
if(t)
{
cout << "t" << endl;
}
}
class Test
{
public:
Test()
{
m_a = 10;
}
~Test()
{
}
operator bool() const
{
return m_a != 0;
}
private:
int m_a;
};
int main()
{
Test t;
if (!t)
{
cout << "!t" << endl;
}
if (t)
{
cout << "t" << endl;
}
}
class Test
{
public:
Test()
{
m_a = 10;
}
~Test()
{
}
bool operator !()
{
return true;
}
operator bool()
{
// 判断代码
return true; //or return false
}
private:
int m_a;
};
int main()
{
Test t;
if (!t)
{
cout << "!t" << endl;
}
if (t)
{
cout << "&t" << endl;
}
}
T* operator &()
{
return rp->p;
}
看来也只能先用取地址搞搞了
class Test
{
public:
Test()
{
m_a = 10;
}
~Test()
{
}
bool operator !()
{
return true;
}
bool operator &()
{
return true;
}
private:
int m_a;
};
int main()
{
Test t;
if (!t)
{
cout << "!t" << endl;
}
if (&t)
{
cout << "&t" << endl;
}
}