Skip to content

Instantly share code, notes, and snippets.

@oxUnd
Last active December 28, 2015 04:29
Show Gist options
  • Save oxUnd/7442266 to your computer and use it in GitHub Desktop.
Save oxUnd/7442266 to your computer and use it in GitHub Desktop.
//
// 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