Created
September 26, 2014 07:27
-
-
Save sergeant-wizard/17fcdb434e8986039f2e to your computer and use it in GitHub Desktop.
return value inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class Super{ | |
public: | |
virtual void func(){ | |
std::cout << "super" << std::endl; | |
} | |
virtual Super* someFunc(){ | |
std::cout << "Super::someFunc()" << std::endl; | |
return nullptr; | |
} | |
}; | |
class Sub: public Super{ | |
public: | |
void func() override{ | |
std::cout << "sub" << std::endl; | |
} | |
virtual Sub* someFunc()override{ | |
std::cout << "Sub::someFunc()" << std::endl; | |
return nullptr; | |
} | |
}; | |
int main(){ | |
Super* a = new Sub; | |
a->func(); | |
a->someFunc(); | |
delete a; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment