Skip to content

Instantly share code, notes, and snippets.

@sergeant-wizard
Created September 26, 2014 07:27
Show Gist options
  • Save sergeant-wizard/17fcdb434e8986039f2e to your computer and use it in GitHub Desktop.
Save sergeant-wizard/17fcdb434e8986039f2e to your computer and use it in GitHub Desktop.
return value inheritance
#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