How to call a non-const method from a const method?
问题 I've got a const method in my class, which cannot be changed to non-const. In this method, I need to call a non-const method but the compiler doesn't let me do that. Is there any way around it? Here is a simplified sample of my code: int SomeClass::someMethod() const { QColor saveColor = color(); setColor(QColor(255,255,255)); // Calling non-const method // .... setColor(saveColor); // restore color return 1; } 回答1: One of the challenges of doing const -correctness is you can't do it halfway.