0
我在C++ CLI(Game.h)一個頭文件用來初始化一個屬性(MAGIC_SEA)受管理的靜態類(在C#)( settings.dll)。然而,當我建立這個代碼(使用CLR支持)引發以下錯誤:通過使用<strong>C#</strong>一個DLL調用從C++ CLI(.NET)
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;
...
}
}
編譯錯誤是相當平淡,「設置」是一個命名空間的名稱,而不是一個類型名稱。所以編譯器還不知道「game_id」是什麼意思。什麼「靜態類」可能意味着很難猜測,這與有效的C++/CLI代碼沒有任何關係。一個變量聲明必須總是出現在一個ref類中,相當於一個const是'literal'。 –
漢斯,是的,「設置」是一個命名空間,但我似乎沒有得到「編譯器還不知道什麼是game_id」的意思。 – ekremer
C++使用單通編譯模型。聲明必須始終出現在定義之前和用法,這與C#非常不同,掌握C++的相關知識對於編寫正確的C++/CLI代碼非常重要,並且發佈可識別的代碼對於獲得SO答案很重要,請考慮從團隊成員那裏獲得幫助。 –