C++/CLI转发声明

C++/CLI forward declarations

本文关键字:声明 转发 CLI C++      更新时间:2023-10-16

我有一个标题如下:

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

如果我的ref类不使用头,我就不能在同一个程序集中使用它。但是有了这个头,我的代码就不再编译了。

这是前两个错误:

c: \开发。。。\xy.dll:警告C4944:"ISYSession":Das Symbol kann nicht aus"c:\develop。。。\"xy.dll"importiert werden:"Dummy::ISYSession"是Bereich vorhanden的缩写。

(英文:"‘摘要::ISYSession’:无法从xy.dll导入符号:Dummy::ISYSsession已存在于当前作用域中。")

错误C3699:"^":Diese Referenzierung kann nicht für den Typ"Schleupen::CS::SY::ISYSession"verwendet werden。

(英文:"此引用不能用于类型‘Dummy::ISYSession’。")

这是怎么回事?对我来说,编译器似乎认为ISYSession ref类是在同一个程序集中定义的(事实并非如此,它是在不同的.NET DLL中定义的)。

    ref class ISYSession {};

这不是正向声明,而是一个没有成员的类的实际类定义。修复:

    ref class ISYSession;