0
votes

I have a native class in C++ and a managed class in C++/CLI. The C++/CLI is a wrapper for the C++. Both classes have the same name, but exist in different namespaces. For some reason I haven't yet grasped, I am receiving compiler errors regarding trying to declare pointers to the managed class, but my code is in fact trying to declare pointers to the native class using fully qualified names. What gives?

"Native\Header.h"

namespace Native
{
    class MyClass {};
}

"Managed/Header.h"

namespace Native { class MyClass; }
// Or
class Native::MyClass;

namespace Managed
{
    ref class MyClass
    {
        Native::MyClass* m_Native; // Error C3699
    };
}

error C3699: '*' : cannot use this indirection on type 'Managed::MyClass'

1

1 Answers

1
votes

The Visual Studio 2012 C++ compiler accepts that code without complaint.

You may have to upgrade.

Actually, so does the Visual Studio 2010 C++ compiler.

Make sure you have the service pack installed; I tested with

Microsoft (R) C/C++ Optimizing Compiler Version 16.00.40219.01

and the exact code is

// C3699test.cpp : main project file.
// 

namespace Native { class MyClass; }

namespace Managed
{
    ref class MyClass
    {
        Native::MyClass* m_Native; // Error C3699
    };
}

and the compile command line is

cl /c /AI"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0" /Zi /clr /nologo- /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _UNICODE /D UNICODE /EHa /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\" /Fd"Debug\vc100.pdb" /TP /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll" /analyze- /errorReport:prompt c3699test.cpp /clr:nostdlib