3

my_project.h

#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;
};

在其他文件中一切正常,但在这里,我做错了什么?

预计到达时间:

我已经像这样修改了函数:

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

它并没有解决问题,但由于某种原因,如果我将返回类型更改为void,那么一切正常

4

1 回答 1

0

我重新创建了您的问题,并得到了同样的错误。删除参数const Foo* foo(使方法 DoSomething 不带参数)删除了错误。我也尝试添加typedef char* Foo;,错误也消失了。

检查您的定义Foo,看起来这就是错误所在。


我将您的代码复制并粘贴到 Visual Studio 中,类型没有错误MyManagedClass。如果我们要找到错误,您需要向我们展示更多代码。

也许MyManagedClass在您忘记using namespace指令的命名空间中?

于 2013-01-23T17:15:44.157 回答