By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,245 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,245 IT Pros & Developers. It's quick & easy.

template members in a non-template class

P: n/a

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.
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Nico Massi wrote:
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.

--
WW aka Attila
Jul 19 '05 #2

P: n/a
On Fri, 29 Aug 2003 20:07:01 +0300, White Wolf <wo***@freemail.hu> wrote:
Nico Massi wrote:
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.

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
Jul 19 '05 #3

P: n/a
Nico Massi <de********@gmx.de> writes:
On Fri, 29 Aug 2003 20:07:01 +0300, White Wolf <wo***@freemail.hu> wrote:
Nico Massi wrote:
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.

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
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.