template members in a non-template class

N

Nico Massi

Hi NG!

I have a class A that should store a vector of pointers to objects of class
B.
But class B contains a template argument and each of the stored objects in
class A could have a different template argument. So i need a way to store
an array of template objects in a non-template class. Obviously this wont
work
cause a can`t tell the compiler which template argument to use.
So whats the usual way to solve such a situation?

The first solution that comes to my mind is, create a non-template base
interface to class B and store pointers to that base interface in A.
But i think this is not the best solution for that kind of problem.
 
W

White Wolf

Nico said:
Hi NG!

I have a class A that should store a vector of pointers to objects of
class B.
But class B contains a template argument and each of the stored
objects in class A could have a different template argument. So i
need a way to store an array of template objects in a non-template
class. Obviously this wont work
cause a can`t tell the compiler which template argument to use.
So whats the usual way to solve such a situation?

The first solution that comes to my mind is, create a non-template
base interface to class B and store pointers to that base interface
in A.
But i think this is not the best solution for that kind of problem.

IMHO you are trying to do some very suspicious desing. I suggest that you
give us a higher level view of this problem (like: I want to handle
different complex numbers). Try stay away in that case from C++ terms (if
it is feasible) and just try to define the problem. I guess there should be
an easier solution.
 
N

Nico Massi

IMHO you are trying to do some very suspicious desing. I suggest that
you
give us a higher level view of this problem (like: I want to handle
different complex numbers). Try stay away in that case from C++ terms
(if
it is feasible) and just try to define the problem. I guess there should
be
an easier solution.


ok here is what i will do:
i would be able to configure my app with a config file where i could set
some values
mostly there are simple values ( int, float, string would cover around 80% )
but i would also be able to read complex types like a 3D Vector or an RGB
color value
so i thought templates would be the way to go for the config values

for the config values i need a class that known all possible config values
by their name
the values would be saved in a config class where the app can query the
config for a value
by specifying its name
 
L

llewelly

Nico Massi said:
ok here is what i will do:
i would be able to configure my app with a config file where i could
set some values
mostly there are simple values ( int, float, string would cover around 80% )
but i would also be able to read complex types like a 3D Vector or an
RGB color value
so i thought templates would be the way to go for the config values

for the config values i need a class that known all possible config
values by their name
the values would be saved in a config class where the app can query
the config for a value
by specifying its name

hm. Maybe boost::any is helpful?

http://boost.org/doc/html/any.html
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top