Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Ineritance
//Title of this code #include <iostream> using namespace std; class A { public: int a,b; public: A(int, int); virtual ~A(){} virtual void add(int); virtual void print(); }; class B : public A { int c; public: B(int, int, int); B(int, int); virtual ~B(){} virtual void add(int); virtual void print(); }; A::A(int x, int y): a(x), b(y) {} B::B(int x, int y): A(x, y){} B::B(int x, int y, int z): A(x, y) { c = z; } void A::add(int n){ a += n; b += n; } void B::add(int n){ a += n; b += n; c += n; } void A::print() { cout << a << " " << b << endl; } void B::print() { cout << a << " " << b << " " << c << endl; } int main() { //B b(1,2,3); A* b = new B(1,2,3); b->print(); dynamic_cast<B*>(b)->print(); cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
Divide
Point on a ray--2133
1
single_digit
Dar
simple serialization
float precision test
Operator Overload
articulation points and bridges
numberOftweets