C++/CLI forward declarations

2019-08-10 05:42发布

问题:

I have a header looking like this:

    namespace Dummy
    {
        ref class ISYSession {};

        namespace Afw
        {
            /// <summary>Sammlung von AFW-Utility-Methoden</summary>
            public ref class AfwUtility
            {
            public:
                static void CopyAFWParamsToIDictionary(AFWParams &parameterIn, System::Collections::IDictionary^ parameterOut);
                static AFWParams* CopyIDictionaryToAFWParams(System::Collections::IDictionary^ dictionary);
                static void ShowExceptionLog(System::String^ sessionId);
                static void ShowStatementLog(System::String^ sessionId);
                static Dummy::ISYSession^ GetSession(AFWAppClass *acl);
            };
        }
    }

If I don't use the header for my ref class I can't use it in the same assembly. But with this header my code doesn't compile anymore.

These are the first two errors:

c:\develop...\xy.dll : warning C4944: 'ISYSession' : Das Symbol kann nicht aus 'c:\develop...\xy.dll' importiert werden: 'Dummy::ISYSession' ist bereits im aktuellen Bereich vorhanden.

(english: "'Dummy::ISYSession': The symbol can't be imported from xy.dll: Dummy::ISYSession already exists in the current scope.")

error C3699: "^": Diese Referenzierung kann nicht für den Typ "Schleupen::CS::SY::ISYSession" verwendet werden.

(english: "This reference can't be used for Type 'Dummy::ISYSession'.")

How is this supposed to work? For me it seems that the compiler thinks that the ISYSession ref class is defined in the same assembly (which it isn't, it's defined in a different .NET DLL).

回答1:

    ref class ISYSession {};

That's not a forward declaration, that's an actual class definition for a class with no members. Fix:

    ref class ISYSession;