fork download
  1. #include <iostream>
  2.  
  3. struct S
  4. {
  5. void print() const { std::cout << "const method" <<std::endl; };
  6. void print() { std::cout << "non-const method" <<std::endl; };
  7. };
  8.  
  9. int main()
  10. {
  11. S const s1;
  12. s1.print(); // prints "const method"
  13. S s2;
  14. s2.print(); // prints "non-const method"
  15. return 0;
  16. };
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
const method
non-const method