gpt4 book ai didi

c++-cli - 语法错误 : missing ';' before '^' in c++ managed

转载 作者:行者123 更新时间:2023-12-05 08:01:18 25 4
gpt4 key购买 nike

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,那么一切正常

最佳答案

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

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


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

MyManagedClass 是否在您忘记了 using namespace 指令的命名空间中?

关于c++-cli - 语法错误 : missing ';' before '^' in c++ managed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14483934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com