C++ cli 如何在托管c++;参考类 我试图通过遵循本教程创建托管C++类,但是当我尝试使用命名空间系统系统:String *Smig < /强>时,它总是给我一个错误,说

C++ cli 如何在托管c++;参考类 我试图通过遵循本教程创建托管C++类,但是当我尝试使用命名空间系统系统:String *Smig < /强>时,它总是给我一个错误,说,c++-cli,C++ Cli,不支持指向C++/Cli ref类或接口类的普通指针 允许 你好。h using namespace System; ref class Hello { public: System::String *_msg; Hello(System::String *Msg); }; hello.cpp文件 #include "Hello.h" using namespace System; Hello::Hello(System::String *Msg) { Msg =

不支持指向C++/Cli ref类或接口类的普通指针 允许

你好。h

using namespace System;
ref class Hello
{

public:
    System::String *_msg;
    Hello(System::String *Msg);
};
hello.cpp文件

#include "Hello.h"
using namespace System;


Hello::Hello(System::String *Msg)
{
    Msg = _msg;
    Console::WriteLine(Msg);
}
void main() {
    Hello ^ h = gcnew Hello("hello world");

}

不要使用非托管的
*
指针,而是使用托管指针
^
符号:

using namespace System;

    ref class Hello
    {
    public:
        System::String ^_msg;
        Hello(System::String ^Msg);
    };
    #include "Hello.h"
    using namespace System;

    Hello::Hello(System::String ^Msg)
    {
        Msg = _msg;
        Console::WriteLine(Msg);
    }
    void main() {
        Hello ^ h = gcnew Hello("hello world");
    }

不要使用非托管的
*
指针,而是使用托管指针
^
符号:

using namespace System;

    ref class Hello
    {
    public:
        System::String ^_msg;
        Hello(System::String ^Msg);
    };
    #include "Hello.h"
    using namespace System;

    Hello::Hello(System::String ^Msg)
    {
        Msg = _msg;
        Console::WriteLine(Msg);
    }
    void main() {
        Hello ^ h = gcnew Hello("hello world");
    }

为什么不将其设为托管指针(^)?据我所知,System::String是一个ref类,不能使用普通指针。对托管代码和ref类使用托管指针/句柄
^
。为什么不将其设为托管指针(^)?据我所知,System::String是一个ref类,不能使用普通的指针。对托管代码和ref类使用托管指针/句柄
^
。感谢更快的响应。感谢更快的响应。