Question

My Class is defined with: (snippet)

public ref class PixelFormatDescriptor
{
  public:
    PixelFormatDescriptor();
    PixelFormatDescriptor(PIXELFORMATDESCRIPTOR *pfd);

    const PIXELFORMATDESCRIPTOR* operator*(System::Drawing::GLSharp::PixelFormatDescriptor ^p)
    {
      return m_pfd;
    }
...
  private:
    PIXELFORMATDESCRIPTOR *m_pfd;
};

I am attempting to use it with the following:

PixelFormatDescriptor ^pfd = new PixelFormatDescriptor();
::ChoosePixelFormat(m_hdc, pfd);

My problem is that ChoosePixelFormat expects pfd to be a const PIXELFORMATDESCRIPTOR *, how would i fix the operator overload to allow me to pass a PixelFormatDescriptor ^ and have it return the PIXELFORMATDESCRIPTOR * automatically without having to implement a named property or a Get method.

Was it helpful?

Solution 2

I have been through many many pages on google, and found that the documentation on overloading operators is quite lacking, but i have found the answer:

the operator overload should be

operator const PIXELFORMATDESCRIPTOR*()
{
  return m_pfd;
}

thought i would put the answer on here just in case anybody else needs this answer.

OTHER TIPS

Here's the way to define that same conversion operator, but as a static method, which is believe is more standard in managed-land.

static operator PIXELFORMATDESCRIPTOR* (PixelFormatDescriptor ^p)
{
    return p->m_pfd;
}

And here's the page that documents the syntax:

http://msdn.microsoft.com/en-US/library/vstudio/047b2c75.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top