C++ cli …阵列<;对象^>;^args

C++ cli …阵列<;对象^>;^args,c++-cli,C++ Cli,我正在读C++/CLI。我看到这些东西: Object^ CreateInstanceFromTypename(String^ type, ...array<Object^>^ args) { if (!type) throw gcnew ArgumentNullException("type"); Type^ t = Type::GetType(type); if (!t) throw gcnew ArgumentException("Invalid type name"); Ob

我正在读C++/CLI。我看到这些东西:

Object^ CreateInstanceFromTypename(String^ type, ...array<Object^>^ args)
{
if (!type)
throw gcnew ArgumentNullException("type");
Type^ t = Type::GetType(type);
if (!t)
throw gcnew ArgumentException("Invalid type name");
Object^ obj = Activator::CreateInstance(t, args);
return obj;
}
什么是…数组^args?如果我删除,有一个错误:

error C2665: 'CreateInstanceFromTypeName' : none of the 2 overloads could convert all the argument types
1>        .\myFourthCPlus.cpp(12): could be 'System::Object ^CreateInstanceFromTypeName(System::String ^,cli::array<Type> ^)'
1>        with
1>        [
1>            Type=System::Object ^
1>        ]
1>        while trying to match the argument list '(const char [86], const char [21])'
错误C2665:'CreateInstanceFromTypeName':两个重载都不能转换所有参数类型
1> .\myFourthCPlus.cpp(12):可以是“System::Object^CreateInstanceFromTypeName(System::String^,cli::array^)”
1> 与
1>        [
1> 类型=系统::对象^
1>        ]
1> 尝试匹配参数列表时“(const char[86],const char[21])”

>

类似C++,C++/CLI有一个可变数量的参数的机制。这就是

..array^
参数前面的
..
的意思

为了类型安全,C++/CLI设计器添加了托管语法来声明变量数组的类型

由于它只是将该参数传递给
Activator::CreateInstance()
函数,因此我将了解Activator函数正在查找哪些变量参数

error C2665: 'CreateInstanceFromTypeName' : none of the 2 overloads could convert all the argument types
1>        .\myFourthCPlus.cpp(12): could be 'System::Object ^CreateInstanceFromTypeName(System::String ^,cli::array<Type> ^)'
1>        with
1>        [
1>            Type=System::Object ^
1>        ]
1>        while trying to match the argument list '(const char [86], const char [21])'