【发布时间】:2011-02-16 11:41:59
【问题描述】:
我使用简单的布尔指针类成员。分配错误的resp。 true 表现不同 - 请参阅代码中的 cmets。 我在下面评论一个来测试另一个。
我使用编译器调用g++ -o basic basic.cpp
class Test
{
public:
int a;
bool* abool;
};
int main() {
Test t;
//t.abool = false; // WORKS
//t.abool = true; // ERROR: cannot convert 'bool' to 'bool*' in assignment - expected IMO;
// this should work for both values IMO
//*(t.abool) = true; // Segmentation fault
//*(t.abool) = false; // Segmentation fault
cout << t.abool << endl;
return 0;
}
【问题讨论】: