Created
March 25, 2018 12:26
-
-
Save sodastsai/5e6a17638addad678e04afe7cf843256 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// clang main.cpp -lstdc++ -std=c++14 -o main | |
#include <iostream> | |
#include <string> | |
class A { | |
public: | |
std::string name() { | |
return "A"; | |
} | |
}; | |
class B: public A { | |
public: | |
std::string name() { | |
return "B"; | |
} | |
}; | |
int main(int argc, const char *argv[]) { | |
A a; | |
B b; | |
std::cout << "A: " << a.name() << std::endl; | |
std::cout << "B: " << b.name() << std::endl; | |
std::cout << "B (as A): " << static_cast<A>(b).name() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment