相关疑难解决方法(0)

为什么当我转换为"long"时会调用"operator bool()"?

我有以下课程:

class MyClass {
public:
   MyClass( char* what ) : controlled( what ) {}
   ~MyClass() { delete[] controlled; }
   operator char*() const { return controlled; }
   operator void*() const { return controlled; }
   operator bool() const { return controlled != 0; }

private:
   char* controlled;
};
Run Code Online (Sandbox Code Playgroud)

这是使用具有以下typedef的Microsoft SDK编译的:

typedef long LONG_PTR;
typedef LONG_PTR LPARAM;
Run Code Online (Sandbox Code Playgroud)

调用代码执行以下操作:

MyClass instance( new char[1000] );
LPARAM castResult = (LPARAM)instance;
// Then we send message intending to pass the address of the buffer inside MyClass
::SendMessage( …
Run Code Online (Sandbox Code Playgroud)

c++ casting operators visual-c++

2
推荐指数
2
解决办法
1647
查看次数

标签 统计

c++ ×1

casting ×1

operators ×1

visual-c++ ×1