我有这段代码:
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);
}
};
当我编译它时,我得到错误:
'pathName' : redefinition; different type modifiers
它在线生成此错误:
NativeDll(pathName);
将路径名更改为任何内容都会产生相同的错误。为什么我收到此错误?
答案 0 :(得分:0)
在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);
}