std :: vector <t *,std :: allocator <t * =“”>&gt;的奇怪的intellisense错误在visual c ++ 2012中</t *,>

时间:2014-02-08 03:47:46

标签: c++ vector intellisense visual-c++-2012

当我在Visual C ++ 2012中编写这个简单的代码时,我得到了一个有趣的intellisense错误: 类型

的引用
"std::vector<Node*, std::allocator<Node*>> &" (non const-qualified)
无法使用类型

的值初始化

"std::vector<Node*, std::allocator<Node*>>".

但我们可以成功构建代码而不会出现警告和错误。那么为什么Visual C ++ 2012会报告这样的智能感知错误呢?

#include <vector>

using std::vector;

class Node {
private:
    vector<Node*> children; 
public: 
    vector<Node*>& getChildren() {
        return children;
    }

    void addChild(Node* child) {
        children.push_back(child);
    }
};

void f(Node* root)
{
    vector<Node*>& tmp = root->getChildren(); // intellisense error on 'root' here
}

void main()
{
    Node root;
    Node child1, child2;
    root.addChild(&child1);
    root.addChild(&child2);
    f(&root);   
}

0 个答案:

没有答案