Topic: Problem with pointers


Author: hsssed@jabba (BELDONA, SRINATH)
Date: Sun, 12 Dec 1993 09:50:00 GMT
Raw View
Hi,
 I have a little experiance in C++. Currently I am working on a C++
prject. I have the following problem.

I have an organization like the following.

   STM
    |
  __________________
  |        |       |
  lst      gst     sst

where STM will send similar commands (e.g. update_xyz()) to all the tables. The
outside world interface to STM will tell STM what command to send and to whom.
STM maintains the pointers to all the three tables.

For example like lst* ptr2lst ,gst* ptr2gst,sst* ptr2sst. STM also maintains
an integer variable which tells on which table it has to act upon.
For example table = 0 means, operate on lst, table = 1 means operate on gst etc..
I want to use only one pointer to kickoff the operation on the lst,gst or sst.

Say for example I need to call update_xyz() on one of the tables, then I would
like to call

 as   return(ptr2curr_table->update_xyz());

 where ptr2curr_table points to one of the tables based on table value

 How do I make ptr2curr_table point to one of the tables given a table
 value ?

 The whole idea is not to write a piece of code like this,

 switch(table)
 {
  case 0:
   return(ptr2lst->update_xyz());
   break;
  case 1:
   return(ptr2lst->update_xyz());
   break;
  case 2:
   return(ptr2lst->update_xyz());
   break;
 }

 Instead of all that I would like to write a single line of code

 like return(ptr2curr_table->update_xyz());

 STM ,lst,gst,sst all are different class objects.

 Would templates feature of C++ be of any help ?

 I need some help in this regard. I will be thankful for your suggestions.

With regards,
Nagaraj.