c++ const

来源:互联网 发布:linuxmint优化 编辑:程序博客网 时间:2024/06/04 18:57
warning: passing ‘const DependencyGraph’ as ‘this’ argument of ‘const std::vector<int> DependencyGraph::get_head(int)’ discards qualifiers [-fpermissive]
             vector<int> hg = graph.get_head(i);


在const变量上调用non const函数,会产生这样的报错。


其中DependencyGraph是const变量,get_head(int)是non const函数,改正方法是将get_head函数声明为const型


int get_head(int k) const{

     .........

}

0 0
原创粉丝点击