C++ 托管C+中的运算符重载+;
我的类定义为:(snippet) 我正在尝试将其与以下内容一起使用:C++ 托管C+中的运算符重载+;,c++,c++-cli,command-line-interface,managed-c++,C++,C++ Cli,Command Line Interface,Managed C++,我的类定义为:(snippet) 我正在尝试将其与以下内容一起使用: PixelFormatDescriptor ^pfd = new PixelFormatDescriptor(); ::ChoosePixelFormat(m_hdc, pfd); 我的问题是ChoosePixelFormat期望pfd是常量像素格式描述符*,如何修复运算符重载,使我能够传递PixelFormatDescriptor^,并让它自动返回PixelFormatDescriptor*,而无需实现命名属性或Get方法
PixelFormatDescriptor ^pfd = new PixelFormatDescriptor();
::ChoosePixelFormat(m_hdc, pfd);
我的问题是
ChoosePixelFormat
期望pfd是常量像素格式描述符*
,如何修复运算符重载,使我能够传递PixelFormatDescriptor^
,并让它自动返回PixelFormatDescriptor*
,而无需实现命名属性或Get方法。我在google上浏览了很多页面,发现关于重载运算符的文档非常缺乏,但我找到了答案:
操作员过载应为
operator const PIXELFORMATDESCRIPTOR*()
{
return m_pfd;
}
我想我会把答案放在这里,以防万一其他人需要这个答案。这里是定义同一个转换运算符的方法,但作为一种静态方法,这被认为是管理土地中更标准的方法
static operator PIXELFORMATDESCRIPTOR* (PixelFormatDescriptor ^p)
{
return p->m_pfd;
}
下面是记录语法的页面:
这称为转换运算符。希望这将有助于您的谷歌搜索:)
static operator PIXELFORMATDESCRIPTOR* (PixelFormatDescriptor ^p)
{
return p->m_pfd;
}