2013-06-13 35 views
0

我有一個C++/Cli和本地混合的項目。我創建了一個自定義對象,並且我想創建一個該對象類型的列表似乎並不好。這裏是代碼:如何創建列表<自定義對象>

#pragma once 
#include <windows.h> 
#include <stdio.h> 
#include "..\..\Toolkit\Include\TypeHelper_h.h" 
using namespace System; 
using namespace System::Runtime::InteropServices; 
using namespace System::Threading; 
using namespace System::Collections::Generic; 

namespace TypeHelperControl { 

public ref class MyClass 
{ 
public: 
    MyClass(){List<TypeVariable^>^ m_someObj;}; 
    ~MyClass(); 

private: 

}; 


public ref class TypeVariable 
{ 
public: 

    TypeVariable(String^ VariableName,String^ VariableType,String^ VariableValue) 
    { 
     this->m_Name = VariableName; 
     this->m_Type = VariableType; 
     this->m_Value = VariableValue; 
    }; 
    String^ get_Name() 
    { 
     return m_Name; 
    } 
    String^ get_Type() 
    { 
     return m_Type; 
    } 
    String^ get_Value() 
    { 
     return m_Value; 
    } 
private: 
    String^ m_Name; 
    String^ m_Type; 
    String^ m_Value; 
}; 

}; 

List^m_someObj;正在生成多個錯誤

 
error C2059: syntax error : '>' 
error C2065: 'VariableType' : undeclared identifier 
error C1004: unexpected end-of-file found 

謝謝

+3

這應該是'名單 ^'至於其他錯誤,請發表您的代碼和詳細的錯誤信息。 –

+1

我希望你也包含TypeVariables.h文件,如C++所要求的。 –

回答

1

你有你的第一次使用之前定義「的TypeVariable」:

public ref class TypeVariable 
{ 

}; 

public ref class MyClass 
{ 
public: 
    MyClass() 
    { 
     List<TypeVariable^>^ m_someObj; 
    } 
}; 
1
 
error C2065: 'VariableType' : undeclared identifier 

我相信這個錯誤是因爲在文件中的這點引起的,編譯器還沒有看到類TypeVariable呢。我建議將您的類重新組織爲單獨的頭文件,並將它們適當地包括在內,但快速的解決方案是將public ref class TypeVariable;前向聲明貼在MyClass的定義之上。

 
error C2059: syntax error : '>' 
error C1004: unexpected end-of-file found 

當上述錯誤得到解決時,這些錯誤應該消失。

相關問題