错误C2059语法错误:'public'

问题描述 投票:-1回答:1

当我尝试构建项目时,我在HelloWorld.h文件的第一个“公共”中收到此错误“错误C2059语法错误:'public'”。看起来它还在期待其他东西,但我是这方面的新秀。我也尝试使用ref而不是__gc作为新的语法规则。

有没有人知道这里可能缺少什么?

提前致谢。

HelloWorld.h

#using <mscorlib.dll>
#using "CSharpHelloWorld.netmodule"

using namespace System;

public __gc class HelloWorldC
{
    public:
        // Provide .NET interop and garbage collecting to the pointer.
        CSharpHelloWorld __gc *t;
        HelloWorldC() {
            t = new CSharpHelloWorld();
            // Assign the reference a new instance of the object
        }

     // This inline function is called from the C++ Code
        void callCSharpHelloWorld() {
            t->displayHelloWorld();
        }
};
c++ visual-studio
1个回答
2
投票
  1. 在第6行使用ref class而不是__gc class
  2. 在第10行使用^而不是__gc *
  3. 在第12行改变使用gcnew而不是new
  4. your project Properties中的公共语言运行时支持(/ clr)
© www.soinside.com 2019 - 2024. All rights reserved.