bool 在vector中用时会有些限制, 比如
vector<bool> m;
bool *p = &m[0];
这种使用指针或者引用的地方就会出错, 原因是在vector里会自动将8个bool拼成1个以节省空间.
这个不知道做STL的那些人怎么想的.为了解决这个问题,实现了一个模拟bool的类, 可以使用vector了
class BOOL
{
public:
BOOL ( void ) { cData = 0; }
BOOL ( int data )
{
if ( data != 0 )
cData = 1;
else
cData = data;
}
void operator = ( int data )
{
if ( data != 0 )
cData = 1;
else
cData = data;
}
operator bool( void )
{
return cData !=0;
}
bool operator ! ( void )
{
return !cData;
}
private:
char cData;
};