Last active
December 28, 2015 04:29
-
-
Save oxUnd/7442266 to your computer and use it in GitHub Desktop.
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
// | |
// virtual.cpp | |
// | |
#include "virtual.h" | |
Base::~Base() { | |
} | |
int ChildA::print(const char * s) { | |
std::cout << "+class ChildA+" << std::endl; | |
std::cout << s << std::endl; | |
std::cout << "-class ChildA-" << std::endl; | |
return 1; | |
} | |
int ChildB::print(const char * s) { | |
std::cout << "+class ChildB+" << std::endl; | |
std::cout << s << std::endl; | |
std::cout << "-class ChildB-" << std::endl; | |
return 1; | |
} | |
void print(Base * printer, const char * s) { | |
printer->print(s); | |
} | |
void virtual_go() { | |
std::cout << "<<virtual_go start>>" << std::endl; | |
ChildA * p_a = new ChildA; | |
ChildB * p_b = new ChildB; | |
print(p_a, "hahahahah"); | |
print(p_b, "hahahhahh"); | |
delete p_a; | |
delete p_b; | |
std::cout << "<<virtual_go end>>" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment