Various C++ Examples (including IPC)  Version: 1.0.0
virtuals.cc File Reference

basic virtual function / class usage More...

#include <iostream>
Include dependency graph for virtuals.cc:

Go to the source code of this file.

Classes

class  AbstractClass
 A basic abstract Class (that is inherited from) More...
 
class  BaseClass
 class that inherits from AbstractClass More...
 
class  ChildClass
 class that inherits from BaseClass -> AbstractClass More...
 
class  AnotherChildClass
 another example of ChildClass (inherits from BaseClass) More...
 

Functions

void callPrint (AbstractClass &p)
 print something More...
 
int main (int argc, char **argv)
 demonstrate virtual functions and abstract classes More...
 

Detailed Description

basic virtual function / class usage

Definition in file virtuals.cc.

Function Documentation

void callPrint ( AbstractClass p)

print something

Definition at line 46 of file virtuals.cc.

References AbstractClass::print().

Referenced by main().

47 {
48  //call the appropriat function (based on the actual type of
49  //BaseClass -be it derived or not)
50  p.print();
51 }
virtual void print()=0

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

demonstrate virtual functions and abstract classes

Definition at line 54 of file virtuals.cc.

References callPrint().

55 {
56  BaseClass b;
57  ChildClass c;
59 
60  //concrete behavior
61  callPrint(b);
62 
63  //polymorphic behavior
64  callPrint(c);
65 
66  //concrete (hiarchial) behavior
67  callPrint(a);
68 }
another example of ChildClass (inherits from BaseClass)
Definition: virtuals.cc:37
void callPrint(AbstractClass &p)
print something
Definition: virtuals.cc:46
class that inherits from BaseClass -> AbstractClass
Definition: virtuals.cc:28
class that inherits from AbstractClass
Definition: virtuals.cc:18

Here is the call graph for this function: