fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class X {
  5. public:
  6. void f() { cout<<"Non const"<<endl; }
  7. void f() const { cout<<"Const"<<endl; }
  8. };
  9.  
  10. int main() {
  11. X x1;
  12. const X x2;
  13. x1.f(); // the best viable is non const if it's non commented out.
  14. x2.f(); // the non const is not possible for a const object.
  15. return 0;
  16. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Non const
Const