Newbie: pointer to templated abstract base class

Joined
Oct 2, 2009
Messages
2
Reaction score
0
Guys,
sorry to ask, but I am trying to create a menu system to a bunch of parameter handlers whose intrinsic values could be int, float, enum etc.

After some thought, I have tried the following implementation:-
1. An abstract interface class, templated
Code:
template <class T>
class ComParmIF{
public:
  virtual T    GetValue(void)=0;
// common to all types, does not neeed template class
  virtual void GetValString(char *,int )=0;//parameter value as string max n chars
...
};
2. several types of class to instantiate the template, e.g.

Code:
class FP_Parameter:public ComParmIF<float>{
public:
//stuff derived from ComParmIF
  virtual float 	GetValue(void);
  virtual void GetValString(char *, int);//parameter value as string max n chars

...
private:
float value;
};

3. Declare FP_Parameters
Code:
FP_Parameter RejectControl;
And this all compiles quite nicely, so I can call their interface functions with varying data types. (I would have used overloading, it looks simpler, but overloading doesn't look at the return type.)

But here's the problem...

When I want to create an array of pointers to my parameter handlers so I can navigate the array as a dynamic menu...the base class (being templated) cannot be used as a data-type. But an array of base class pointers is exactly what I want here.

i.e.

Code:
ComParmIF *menuitem = &RejectControl;
Fails miserably :(

As this is my first C++ project, I reckon I am going about this the wrong way.

Any ideas?

Thanks
 
Joined
Oct 2, 2009
Messages
2
Reaction score
0
Newbie: Ignore me

Bad form to bump the thread...but to let you know that I found the flaw in my own thinking and designed a work-around that doesn't involve returning unspecified data types to a generic interface.:oops:

The trouble with knowing bits and pieces of other languages is that you forget how strongly typed C++ is, and assume there must be a way to replicate "variant" data types from other languages.

A little knowledge is a dangerous thing, indeed.

Thread closed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top