我已經開始爲我需要的庫編寫一些代碼。下面的代碼給我一個錯誤C++限定符錯誤
class node {
public:
node() { }
node(const node&);
~node() { }
luint getID() { return this->ID; }
node& operator=(const node&);
protected:
luint ID;
std::vector<node*> neighbors;
};
node::node(const node& inNode) {
*this = inNode;
}
node& node::operator=(const node& inNode) {
ID = inNode.getID();
}
是以下幾點:
graph.cpp: In member function 'node& node::operator=(const node&)': graph.cpp:16: error: passing 'const node' as 'this' argument of 'luint node::getID()' discards qualifiers
我做了什麼毛病的代碼?
感謝,
以下兩個鏈接可能interessting爲您:http://en.wikipedia.org/wiki/Const-correctness和http://www.parashift.com/c++-faq -lite/const-correctness.html – Vinzenz 2010-10-13 19:51:25