从C+;调用托管静态类(在C#中)+;CLI(.NET)

从C+;调用托管静态类(在C#中)+;CLI(.NET),.net,c++-cli,clr,.net,C++ Cli,Clr,我在C++CLI(Game.h)中有一个头文件,它使用C(settings.DLL)中的DLL初始化属性(MAGIC#u SEA)。但是,当我构建此代码(使用CLR支持)时,会抛出以下错误: Error 3 error C3083: 'game_id': the symbol to the left of a '::' must be a type c:\users\ed\projectS\Game.h Error 4 error C2039: 'MAGIC_SEA' : is

我在C++CLI(Game.h)中有一个头文件,它使用C(settings.DLL)中的DLL初始化属性(MAGIC#u SEA)。但是,当我构建此代码(使用CLR支持)时,会抛出以下错误:

Error   3   error C3083: 'game_id': the symbol to the left of a '::' must be a type c:\users\ed\projectS\Game.h 
Error   4   error C2039: 'MAGIC_SEA' : is not a member of 'settings'    c:\users\ed\ed\ProjectSl\Game.h 
Game.h

...
using namespace settings;
...
const short MAGIC_SEA = settings::game_id::MAGIC_SEA;
...
settings.dll

using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Collections;
using System.ComponentModel;
using System.Management;
using System.Management.Instrumentation;

namespace settings {
...
public static class game_id {

      public const short MAGIC_SEA = 1;
...
      }    
}

看起来C++/CLI项目没有正确引用C#库。没有引用,C++编译器就不能找到C语言中声明的任何类。

根据Visual Studio版本的不同,在C++/CLI项目中添加引用的步骤可能与其他.NET语言不同,后者在解决方案资源管理器树中显示引用。在较旧Visual Studio版本的C++/CLI项目中,您会发现它们具有编译选项:


编译错误很简单,“设置”是名称空间名称,而不是类型名称。因此编译器还不知道“game_id”是什么意思。很难猜测“静态类”的含义,这与有效的C++/CLI代码无关。变量声明必须始终出现在ref类中,const的等价物是
literal
。Hans,是的,“settings”是一个名称空间,但我似乎不理解它“编译器还不知道GAMEYID意味着什么。C++使用一个单遍编译模型。声明必须始终出现在定义和用法之前。这与C#很不一样。拥有C++的工作知识对于编写正确的C++/CLI代码非常重要。发布可识别的代码对于获得SO答案非常重要。考虑从团队成员那里得到帮助。好的。我会的。谢谢