473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

template members in a non-template class


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
3 2014
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: les_ander | last post by:
Hi, I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the...
3
by: Oren | last post by:
Hi, Is there any way that calls to sp_addrolemember and sp_droprolemember can be enabled for non database owners and non sysadmin members? This would be very helpful for an application I'm in...
5
by: Luther Baker | last post by:
Hi, Is the order of initialization guaranteed for static members as it is for instance members? Namely, the order they appear the in the declaration? ie: foo.h:
10
by: S.Tobias | last post by:
1. If I have a struct type which contains a const member: struct mystruct { const int id; int mutable; }; does a definition struct mystruct ms; define an object `ms' which is *partly* const? ...
43
by: Mark | last post by:
Hello Friends Please check the code below. One in C# and other in VB .Net In C# I am not able to access a static property by an instance variable, but in VB I can do it easily. The Error is ...
3
by: Bari | last post by:
Hi all, I just wanted to know if I can ininialize data members in the header. The compiler (gcc 2.96) returns an error. The data members are not const (I know that const members can't be...
8
by: Rajesh | last post by:
Based on my understanding static members do not have access to non- static members. In the below example static method 'name' accessing non-static method creating reference. Seems to me it is not...
18
by: lovecreatesbea... | last post by:
1. The following code snippet uses minus operation on two pointers to calculate the distance between struct members. This is illegal, right? 2. s1 and s2 are type of the same struct S. Can the...
25
by: jbholman | last post by:
I am pretty new to C and doing my first project in C. I actually read almost the entire FAQ, but can't seem to figure out this problem. I have a structure. I have a list of these structures. ...
1
by: djnokturnal | last post by:
Hey guys/gals, I have successfully implemented forms authentication on my site: <authentication mode="Forms"> <forms loginUrl="/Members/Login.aspx" timeout="20"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.