首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C++/CX:从IVector<T>^转换到Vector<T>^

C++/CX:从IVector<T>^转换到Vector<T>^
EN

Stack Overflow用户
提问于 2013-06-05 16:32:37
回答 1查看 1.2K关注 0票数 1

如何将IVector^转换为向量^?文档涵盖了隐式工作的反向情况,但是当我尝试隐式转换和编译时,它不会编译,但是当我尝试转换它时会引发异常。我已经查过这份推荐信了,但我没能把它包括在内。

原因是我希望将Vector^存储在我的类中,并且只在一个属性中使用IVector与JavaScript通信,因为Vector工作得更快,应该用于内部计算。

谢谢

编辑:我很抱歉我太简短了。这是对局势的更广泛的解释。

代码语言:javascript
运行
复制
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声明:

代码语言:javascript
运行
复制
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;
        }
    }

};
EN

回答 1

Stack Overflow用户

发布于 2013-06-05 16:36:07

这通常是通过safe_cast<T>完成的。

代码语言:javascript
运行
复制
Vector^ asVector = safe_cast<Vector^>(theIVectorHandle);

有关详细信息,请参阅关于C++/CX铸造的MSDN文章

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16945242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档