2013-01-23 40 views
2

my_project.h前:語法錯誤:缺少';' '^' 在C++託管

#pragma once 

#include <vcclr.h> 
#include "MyManagedClass.h" 

namespace my_namespace 
{ 
    MyManagedClass^ DoSomething(const Foo* foo); 
} 

我有下一個錯誤:

1) error C2143: syntax error : missing ';' before '^' 
2) error C4430: missing type specifier - int assumed. 
    Note: C++ does not support default-int 

項目已創建爲c++/cli

"MyManagedClass.h"

public ref class MyManagedClass 
{ 
public: 
System::UInt32 GetMember() 
{ 
    return m_member; 
} 
private: 
System::UInt32 m_member; 
}; 

在其他文件中一切正常,但在這裏,我做錯了什麼?

ETA:

我已經修改了功能類似這樣:

namespace my_namespace 
{ 
    MyManagedClass^ DoSomething(const System::String^ str); 
} 

,並沒有解決問題,但由於某些原因,如果我改變返回類型爲void,然後一切工作正常

+0

Foo的定義在哪裏?在vcclr.h? –

+0

@Carlos Quintanilla,在我的例子中'Foo'是'char *' –

+0

你確定錯誤說:''''在'^'之前而不是在'*'之前? –

回答

0

我重新創建你的問題,並得到相同的錯誤。刪除參數const Foo* foo(使方法DoSomething不帶參數)刪除了錯誤。我也嘗試添加typedef char* Foo;,並且錯誤也消失了。

檢查您的Foo的定義,它看起來像是錯誤所在。


我複製粘貼&代碼到Visual Studio中,有對MyManagedClass型沒有錯誤。如果我們要查找錯誤,則需要向我們展示更多代碼。

也許是MyManagedClass在命名空間中,您忘記了using namespace指令?

+0

在我看來,返回類型中的問題,如果我使它無效,錯誤消失 –

+0

您需要向我們展示更多代碼以查找錯誤。請參閱編輯。 –