473,385 Members | 1,642 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,385 software developers and data experts.

templated data member

Hello,

I want to have a class which can contain vectors of many different types
(int, double, Complex, etc).

Is it possible to have a generic vector inside a non-template class?

Thank you,

Dan Elliott
Jul 22 '05 #1
3 1501
Daniel L Elliott wrote:
Hello,

I want to have a class which can contain vectors of many different types
(int, double, Complex, etc).

Is it possible to have a generic vector inside a non-template class?


How would you use the class ?

Perhaps boost::any is somthing like what you're looking for ?
Jul 22 '05 #2
On Fri, 12 Nov 2004 11:18:05 -0800, Gianni Mariani wrote:
Daniel L Elliott wrote:
Hello,

I want to have a class which can contain vectors of many different types
(int, double, Complex, etc).

Is it possible to have a generic vector inside a non-template class?


How would you use the class ?

Perhaps boost::any is somthing like what you're looking for ?

Thank you for your response. Here is a brief description of my usage:

I have a set of transformations. Each is represented by a class which
contains a matrix (uBLAS) which may contain int,float,Complex,etc.
However, transformations are applied by passing images into the class and
therefore the data type of the internal matrix does not really matter.
Can I make the matrix data member generic (template) while not having a
template parameter for the matrix contents (int, float, Complex, etc.)?

Some tranformations are best represented as a matrix of integers while
others must be float. However, I would like them all to fall under the
same data type.

Thank you very much for all responses!

- dan
Jul 22 '05 #3
> Can I make the matrix data member generic (template) while not having a
template parameter for the matrix contents (int, float, Complex, etc.)?


Can I make it generic, without making it generic? Of course the answer is
no.

As already suggested maybe boost::any is what you are looking for.
www.boost.org.

john
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rich | last post by:
Hi, I have a query regarding VC6 and its handling of templated copy constructors. Here goes: Take a look at the following code sample... template<class _Ty, size_t t_uiSize = 10 > class...
5
by: Marijn | last post by:
I recently told g++ (3.2) something to the effect of: template <class T> struct test{ typedef int type; }; template <class T> void f(){ test<T>::type i;
3
by: William Payne | last post by:
Consider this (templated) class member function: template<typename Type> void CircularContainer<Type>::insert(const Type& s) { vector<Type>::iterator itr = find(m_elements.begin(),...
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
1
by: Trevor Morgan | last post by:
I've been having problems when a templated member function has the same name as ANY previously defined template parameter. Here's the simplest case that demonstrates the problem. This fails to...
6
by: Dan Huantes | last post by:
I was presented a problem today where a class had member variable that was an object of a templated class. The class wanted to instantiate the object as a private member variable and call a...
2
by: Amadeus W. M. | last post by:
I have a bunch of templated functions: template <class Type_t> double f2(Type_t x) { return 2*x; } template <class Type_t> double f3(Type_t x) { return 3*x; }
2
by: mattjgalloway | last post by:
I'm having some problems with a templated member function of a templated class. Unfortunately I can't replicate it with a simple example so I know something odd must be going on!!! Basically it's...
5
Banfa
by: Banfa | last post by:
So I have a little problem, I have a template class and that class contains a template function; now what I want to do is declare that function in the class (or indeed the entire class) as a friend...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.