Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 托管C+中的运算符重载+;_C++_C++ Cli_Command Line Interface_Managed C++ - Fatal编程技术网

C++ 托管C+中的运算符重载+;

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方法

我的类定义为:(snippet)

我正在尝试将其与以下内容一起使用:

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;
}