Compiler errors 为什么我在c++/clr

Compiler errors 为什么我在c++/clr,compiler-errors,c++-cli,Compiler Errors,C++ Cli,我有以下代码: public ref class NativeDll { DllInterface *dllInterface; public: NativeDll(String ^dllName) { msclr::interop::marshal_context context; std::string stdDllName = context.marshal_as<std::string>(dllName);

我有以下代码:

public ref class NativeDll
{
    DllInterface *dllInterface;
public:
    NativeDll(String ^dllName)
    {
        msclr::interop::marshal_context context;
        std::string stdDllName = context.marshal_as<std::string>(dllName);

        dllInterface=new DllInterface(stdDllName);
    }
    NativeDll()
    {
        auto assembly= Assembly::GetExecutingAssembly();
        String ^path=Path::GetDirectoryName(assembly->FullName);
        auto pathName=Path::Combine(path,"MyDLL.dll");
        NativeDll(pathName);
    }
};
它会在第行生成此错误:

  NativeDll(pathName);

将路径名更改为任何内容都会产生相同的错误。为什么会出现此错误?

在C++中,不能从另一个构造函数调用构造函数。在C++/Cli AFAIK中也是如此。创建一个两个构造函数都调用的方法:

NativeDll(String ^dllName)
{
    initialize(dllName);
}

NativeDll()
{
    auto assembly= Assembly::GetExecutingAssembly();
    String ^path=Path::GetDirectoryName(assembly->FullName);
    auto pathName=Path::Combine(path,"MyDLL.dll");

    initialize(dllName);
}

void initialize(String ^dllName)
{
    msclr::interop::marshal_context context;
    std::string stdDllName = context.marshal_as<std::string>(dllName);

    dllInterface=new DllInterface(stdDllName);
}
nativedl(字符串^dllName)
{
初始化(dllName);
}
nativedell()
{
auto assembly=assembly::GetExecutionGassembly();
字符串^path=path::GetDirectoryName(程序集->全名);
自动路径名=路径::组合(路径,“MyDLL.dll”);
初始化(dllName);
}
无效初始化(字符串^dllName)
{
msclr::interop::封送上下文;
std::string stdDllName=context.marshal_as(dllName);
dllInterface=新的dllInterface(stdDllName);
}

请将标记从[c++]更改为[c++-cli]或其他内容。
NativeDll(String ^dllName)
{
    initialize(dllName);
}

NativeDll()
{
    auto assembly= Assembly::GetExecutingAssembly();
    String ^path=Path::GetDirectoryName(assembly->FullName);
    auto pathName=Path::Combine(path,"MyDLL.dll");

    initialize(dllName);
}

void initialize(String ^dllName)
{
    msclr::interop::marshal_context context;
    std::string stdDllName = context.marshal_as<std::string>(dllName);

    dllInterface=new DllInterface(stdDllName);
}