C++/CLI forward declarations

吃可爱长大的小学妹 提交于 2019-12-11 03:16:00

问题


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;


来源:https://stackoverflow.com/questions/9110307/c-cli-forward-declarations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!