在同一时间序列:使用管理的阵列和std不兼容 [英] Incompatibility using managed array and std:array at same time
问题描述
我有使用数组像这样(举例来说)我的C ++ / CLI code:
I have my C++/CLI code using arrays like this (for example):
array<String^>^ GetColNames() {
vector<string> vec = impl->getColNames();
array<String^>^ arr = gcnew array<String^>(vec.size());
for (int i = 0; i < vec.size(); i++) {
arr[i] = strConvert(vec[i]);
}
return arr;
}
它编译罚款,直到我的图书馆阵列添加到项目:
It's compiling fine until I add the library "array" to the project:
#include <array>
然后,我不知道如何使用管理CLI数组,因为编译器认为所有声明数组是的std ::阵列
。
错误例子:
array<String^>^ arr
// ^ Error here: "too few arguments for class template "std::array""
gcnew array<String^>(vec.size())
// ^ Error: "Expected a type specifier"
如何解决此问题?我试着删除使用命名空间std
从该文件,但它并没有区别。我应该删除,从该项目的所有其他C ++文件?
How to solve this? I tried removing using namespace std
from that file, but it makes no difference. Should I remove that from every other C++ file on the project?
推荐答案
显然,你有一个使用命名空间std;
范围的某个地方。当心它在.h文件中被使用,如果你不能找到它。
Clearly you have a using namespace std;
in scope somewhere. Watch out for it being used in .h file if you cannot find it.
您可以化解歧义,如的C ++ / CLI扩展的关键字排列的是在 CLI
命名空间。编译没有问题:
You can resolve the ambiguity, the C++/CLI extension keywords like array are in the cli
namespace. This compiles fine:
include "stdafx.h"
#include <array>
using namespace std; // <=== Uh-oh
using namespace System;
int main(cli::array<System::String ^> ^args)
{
auto arr = gcnew cli::array<String^>(42);
return 0;
}
这篇关于在同一时间序列:使用管理的阵列和std不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!