如何將IVector ^轉換爲Vector ^?文檔涵蓋了隱式工作的相反情況,但是當我嘗試隱式轉換和編譯時,這個不會編譯,但是當我嘗試轉換它時引發異常。我已經看過參考書,但是我不能涵蓋這個。C++/CX:從IVector <T> ^轉換爲Vector <T>^
原因是我希望將Vector ^存儲在我的類中,並且僅在屬性中使用IVector才能與JavaScript進行通信,因爲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的一些問題,所以我試圖使用矢量,而不能施放它。這裏的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傳遞。事實證明,這個錯誤沒有任何教育意義,因此我認爲整個線程應該被刪除?抱歉,添麻煩了。 –