c++ 返回值为容器引用,指针时的问题。

发现一个奇怪的问题,mark

class Demo
{
public:
    std::vector<int> *getVector()const;
    int *getInt()const;
private:
    std::vector<int> m_vecInt;
    int m_int;
};

std::vector<int> *Demo::getVector()const //这个const变成修饰返回值了???
{
    return &m_vecInt; //编译出错,无法从"const std::vector<int>* "转换为"std::vector<int>*"
}


int *Demo::getInt()const //ok
{
    return &m_int; 
}

  

猜你喜欢

转载自www.cnblogs.com/quehualin/p/9207797.html