C++/CX:从 IVector<T>^ 转换为矢量<T>^
C++/CX: Converting from IVector<T>^ to Vector<T>^
如何从矢量^转换到矢量^?文档涵盖了隐式工作的相反情况,但是当我尝试隐式转换和编译时,它不会编译,但当我尝试转换它时会引发异常。我已经看过参考资料,但是我无法涵盖这一点。
这样做的原因是我希望将Vector^存储在我的类中,并且仅在与JavaScript通信的属性中使用Vector,因为Vector工作更快,应该用于内部计算。
感谢编辑:我很抱歉太简短了。以下是对情况的更广泛解释。
if(parent->childNodes != nullptr && parent->childNodes->Size > 0)
{
for (uint32 i = 0; i < parent->childNodes->Size; i++)
{
ContentElementsNode^ childNode;
IVector<ContentElementsNode^>^ childNodes = parent->childNodes;
childNode = childNodes->GetAt(i);
Vector<ContentElementsNode^>^ childWords = wordObjects(childNode);
for each (ContentElementsNode^ word in childWords)
result->Append(word);
}
}
函数在第一次调用GetAt(i)行时失败。我认为这可能是一些问题与矢量,所以我尝试使用矢量代替,但无法cast它。下面是ContentElementsNode声明:
public ref class ContentElementsNode sealed
{
private:
IVector<ContentElementsNode^>^ childNodes_;
String^ textContent_;
String^ localName_;
Rectangle boundingBox_;
String^ id_;
public:
ContentElementsNode(void);
property IVector<ContentElementsNode^>^ childNodes {
void set(IVector<ContentElementsNode^>^ value)
{
childNodes_ = value;
}
IVector<ContentElementsNode^>^ get()
{
return childNodes_;
}
}
property String^ textContent {
String^ get() {
return textContent_;
}
void set(String^ value) {
textContent_ = value;
}
}
property String^ localName {
String^ get() {
return localName_;
}
void set(String^ value) {
localName_ = value;
}
}
property Rectangle boundingBox {
Rectangle get() {
return boundingBox_;
}
void set(Rectangle value) {
boundingBox_ = value;
}
}
property String^ id {
String^ get() {
return id_;
}
void set(String^ value) {
id_ = value;
}
}
};
这通常通过safe_cast<T>
:
Vector^ asVector = safe_cast<Vector^>(theIVectorHandle);
有关详细信息,请参阅MSDN关于c++/CX中的强制转换的文章。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 是numeric_limits&lt; int&gt; :: is_modulo从逻辑上矛盾
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- ///<评论></评论>在Visual Studio中