why copy constructor use private property directly in C++
问题 Look at following: class node { int freq; public: node(const node &other) { freq = other.freq; } int getFreq() { return freq; } }; It works well. However, when I replace freq = obj.freq with freq = obj.getFreq() , it gives me this error: 'int node::getFreq(void)': cannot convert 'this' pointer from 'const node' to 'node &' Why? freq is a private member, it makes more sense that we should use the interface getFreq to access it. 回答1: It won't compile, because your function is not declared const