简体   繁体   English

错误C2059语法错误:“公共”

[英]Error C2059 syntax error: 'public'

I'm getting this error "Error C2059 syntax error: 'public'" in the first "public" of the HelloWorld.h file when I try to build the project. 尝试构建项目时,HelloWorld.h文件的第一个“ public”中出现此错误“ Error C2059语法错误:'public'”。 Looks like it's expecting something else but I'm a rookie on this. 看起来还期待其他东西,但是我是这个菜鸟。 I have also tried using ref instead of __gc as the new syntax rules. 我还尝试使用ref代替__gc作为新的语法规则。

Does anybody have a clue of what can be missing here? 有人知道这里可能缺少什么吗?

Thanks in advance. 提前致谢。

HelloWorld.h 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();
        }
};
  1. use ref class instead of __gc class in line 6 在第6行中使用ref class代替__gc class
  2. use ^ instead of __gc * in line 10 在第10行中使用^代替__gc *
  3. use gcnew instead of new in line 12 change 在第12行中使用gcnew代替new
  4. Common Language Runtime Support To (/clr) in your project Properties your project Properties (/ clr)公共语言运行时支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM