如何将IVector^转换为向量^?文档涵盖了隐式工作的反向情况,但是当我尝试隐式转换和编译时,它不会编译,但是当我尝试转换它时会引发异常。我已经查过这份推荐信了,但我没能把它包括在内。
原因是我希望将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;
}
}
};
发布于 2013-06-05 08:36:07
这通常是通过safe_cast<T>
完成的。
Vector^ asVector = safe_cast<Vector^>(theIVectorHandle);
有关详细信息,请参阅关于C++/CX铸造的MSDN文章。
https://stackoverflow.com/questions/16945242
复制