A
Alex Vinokur
Hi,
I need something like "function inheritance".
typedef void (*func_type1) (int);
typedef int (*func_type2) (double);
typedef char (*func_type3) (short, int);
....
I need a vector contains pointers to functions of types above.
Because conceptions "base function" and "derived function" are missing in C++,
it seems that the problem (of creating the vector) should be resolved
by using special base and derived classes/structures.
struct BFunc
{
// Stuff
};
struct DFunc1
{
func_type1 func_;
DFunc1 (func_type1 f) : func_ (f) {}
// Stuff
};
struct DFunc2
{
func_type2 func_;
DFunc2 (func_type2 f) : func_ (f) {}
// Stuff
};
struct DFunc3
{
func_type3 func_;
DFunc3 (func_type3 f) : func_ (f) {}
// Stuff
};
Now, we have
vector<*BFunc> v;
And, for instance
v.push_back (new DFunc2 (f));
v.push_back (new DFunc1 (ff));
v.push_back (new DFunc3 (fff));
v.push_back (new DFunc2 (ffff));
v.push_back (new DFunc1 (fffff));
The questions are:
1) Do we have to use dynamic_cast (while processing vector<*BFunc>)
to call a relevant function via v?
2) Is there any better solution of the "function inheritance" problem?
I need something like "function inheritance".
typedef void (*func_type1) (int);
typedef int (*func_type2) (double);
typedef char (*func_type3) (short, int);
....
I need a vector contains pointers to functions of types above.
Because conceptions "base function" and "derived function" are missing in C++,
it seems that the problem (of creating the vector) should be resolved
by using special base and derived classes/structures.
struct BFunc
{
// Stuff
};
struct DFunc1
{
func_type1 func_;
DFunc1 (func_type1 f) : func_ (f) {}
// Stuff
};
struct DFunc2
{
func_type2 func_;
DFunc2 (func_type2 f) : func_ (f) {}
// Stuff
};
struct DFunc3
{
func_type3 func_;
DFunc3 (func_type3 f) : func_ (f) {}
// Stuff
};
Now, we have
vector<*BFunc> v;
And, for instance
v.push_back (new DFunc2 (f));
v.push_back (new DFunc1 (ff));
v.push_back (new DFunc3 (fff));
v.push_back (new DFunc2 (ffff));
v.push_back (new DFunc1 (fffff));
The questions are:
1) Do we have to use dynamic_cast (while processing vector<*BFunc>)
to call a relevant function via v?
2) Is there any better solution of the "function inheritance" problem?