fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Foo {
  5. public:
  6. std::string getIt() const {
  7. return const_cast<Foo *>(this)->getItNonConst();
  8. }
  9.  
  10. std::string getItNonConst() {
  11. return "Foo";
  12. }
  13. };
  14.  
  15. int main() {
  16. Foo f;
  17. std::cout << f.getIt();
  18. }
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
Foo