【发布时间】:2013-06-05 16:32:37
【问题描述】:
如何将 IVector^ 转换为 Vector^?文档涵盖了隐式工作的相反情况,但是当我尝试隐式转换和编译时这个不会编译,但是当我尝试转换它时会引发异常。我已经查看了参考资料,但无法涵盖。
这样做的原因是我希望将 Vector^ 存储在我的类中,并且仅在与 JavaScript 通信的属性中使用 IVector,因为 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) 行时失败。我认为这可能是 IVector 的一些问题,所以我尝试使用 Vector 但无法转换它。这是 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;
}
}
};
【问题讨论】:
-
函数调用不应在 GetAt() 行失败。你在什么时候用集合初始化后备存储(childNodes_)?
-
前端部分好像有错误,所以通过ABI传递了无效值。事实证明,该错误没有任何教育目的,我认为应该删除整个线程?很抱歉给您带来麻烦。
标签: c++ vector type-conversion c++-cx