Click here to Skip to main content
15,914,160 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: pure virtual functions Pin
Kushagra Tiwari17-Sep-09 20:44
Kushagra Tiwari17-Sep-09 20:44 
GeneralRe: pure virtual functions Pin
Cedric Moonen17-Sep-09 20:53
Cedric Moonen17-Sep-09 20:53 
GeneralRe: pure virtual functions Pin
hrishiS17-Sep-09 20:55
hrishiS17-Sep-09 20:55 
AnswerRe: pure virtual functions Pin
«_Superman_»17-Sep-09 20:44
professional«_Superman_»17-Sep-09 20:44 
AnswerRe: pure virtual functions Pin
Cedric Moonen17-Sep-09 20:51
Cedric Moonen17-Sep-09 20:51 
GeneralRe: pure virtual functions Pin
hrishiS17-Sep-09 21:00
hrishiS17-Sep-09 21:00 
GeneralRe: pure virtual functions Pin
Cedric Moonen17-Sep-09 21:12
Cedric Moonen17-Sep-09 21:12 
GeneralRe: pure virtual functions Pin
CPallini17-Sep-09 22:09
mveCPallini17-Sep-09 22:09 
#include<iostream>

class IDumpable
{
public :
  virtual void  dump()=0;
};


class A: public IDumpable
{
  int _a;
public:
  A(int a):_a(a){}
  virtual void dump(){ std::cout << _a << std::endl;}
};

class B: public IDumpable
{
  static int _counter;
  double _d;
  int _id;
public:
  B(double d):_d(d){_id=B::_counter++;} 
  virtual void dump(){ std::cout << "(" << _id << ") " << _d << std::endl;}
};


int B::_counter=0;


void dump( IDumpable * pid[], int size)
{
  int i;
  for (i=0; i<size; i++)
  {
     pid[i]->dump();
  }
}

void main()
{
  IDumpable *pid[3];
  pid[0] = new A(10);
  pid[1] = new B(5.7);
  pid[2] = new B(10.745);
  dump(pid, sizeof(pid)/sizeof(pid[0]));
}


Here, the function dump can iterate on the passed array without bothering about the exact type of the array elements.
Note that, once the IDumpable interface is written, we can start coding its consumers (for instance the dump function) even if the actual implementations of the interface are not yet provided.

Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

AnswerRe: pure virtual functions Pin
RugbyLeague17-Sep-09 22:09
RugbyLeague17-Sep-09 22:09 
GeneralRe: pure virtual functions Pin
hrishiS17-Sep-09 22:28
hrishiS17-Sep-09 22:28 
GeneralRe: pure virtual functions Pin
RugbyLeague17-Sep-09 22:43
RugbyLeague17-Sep-09 22:43 
AnswerRe: pure virtual functions - an example for you. Pin
Iain Clarke, Warrior Programmer17-Sep-09 23:00
Iain Clarke, Warrior Programmer17-Sep-09 23:00 
QuestionDifferentiating SHUTDOWN and RESTART ? Pin
Kushagra Tiwari17-Sep-09 20:29
Kushagra Tiwari17-Sep-09 20:29 
AnswerRe: Differentiating SHUTDOWN and RESTART ? Pin
«_Superman_»17-Sep-09 20:42
professional«_Superman_»17-Sep-09 20:42 
GeneralRe: Differentiating SHUTDOWN and RESTART ? Pin
Kushagra Tiwari17-Sep-09 20:46
Kushagra Tiwari17-Sep-09 20:46 
QuestionRe: Differentiating SHUTDOWN and RESTART ? Pin
Kushagra Tiwari17-Sep-09 22:25
Kushagra Tiwari17-Sep-09 22:25 
GeneralRe: Differentiating SHUTDOWN and RESTART ? Pin
David Crow18-Sep-09 6:26
David Crow18-Sep-09 6:26 
GeneralRe: Differentiating SHUTDOWN and RESTART ? Pin
kilt21-Sep-09 0:45
kilt21-Sep-09 0:45 
Questionusing boost::bind cause error prj0002 Pin
fley_fly17-Sep-09 19:58
fley_fly17-Sep-09 19:58 
AnswerRe: using boost::bind cause error prj0002 Pin
Stuart Dootson17-Sep-09 20:50
professionalStuart Dootson17-Sep-09 20:50 
QuestionOutlook Automation Pin
john563217-Sep-09 19:29
john563217-Sep-09 19:29 
QuestionWM_LBUTTONUP does not trigger, please help Pin
Isuru_Perera17-Sep-09 19:27
Isuru_Perera17-Sep-09 19:27 
AnswerRe: WM_LBUTTONUP does not trigger, please help Pin
Code-o-mat17-Sep-09 20:36
Code-o-mat17-Sep-09 20:36 
AnswerRe: WM_LBUTTONUP does not trigger, please help Pin
Romualdas Cukuras17-Sep-09 20:36
Romualdas Cukuras17-Sep-09 20:36 
AnswerRe: WM_LBUTTONUP does not trigger, please help Pin
Isuru_Perera17-Sep-09 22:15
Isuru_Perera17-Sep-09 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.