Container for different types of variables



 DEVELOP > c-Plus-Plus > Container for different types of variables

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "m@j3R ;"
Date: 05 Dec 2004 10:55:46 AM
Object: Container for different types of variables
Hello
I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?
----|----------|--|----|------|etc.
var1| var2 |v3|var4| var5 |etc.
int | float |bo|int | char |etc.
m@j3R ;)
.

User: "Siemel Naran"

Title: Re: Container for different types of variables 05 Dec 2004 01:28:38 PM
"m@j3R ;" <majer@agdex.com> wrote in message

I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?

----|----------|--|----|------|etc.
var1| var2 |v3|var4| var5 |etc.
int | float |bo|int | char |etc.

In C++, make a base abstract class Var. Now make classes Int, Float, etc
derived from it. Your container will be a std::deque<Var*>, or to make it
more easily memory safe std::deque<boost::shared_ptr<Var>>. Feel free to
add whatever pure virtual functions you want to class Var. You could make
your hierarchy more elaborate too, such as creating a class Float8 derived
from Float, Float16, etc.
You can use boost::any, as suggested in the other post. Looking at the
code, it seems the same as the above idea, except you don't have to create
class Var, Int, Float etc. So it should suffice in most circumstances.
Another thing is that one can think of std::ostringstream as a container of
heterogenous types.
std::ostringstream container;
container << intVal << ' ' << floatVal << ' ' << charVal << ' ' << boolVal;
.

User: "Mathew Hendry"

Title: Re: Container for different types of variables 05 Dec 2004 11:32:02 AM
On 5 Dec 2004 08:55:46 -0800,
(m@j3R ;) wrote:

I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?

No, but a collection of boost::any's might do the job. http://www.boost.org
-- Mat.
.
User: "Jonathan Turkanis"

Title: Re: Container for different types of variables 05 Dec 2004 11:50:51 AM
"Mathew Hendry" <TJLWBECGSGWU@spammotel.com> wrote in message
news:7bh6r096nr9d9jcd39eokioca96r6259ca@4ax.com...

On 5 Dec 2004 08:55:46 -0800,

(m@j3R ;) wrote:

I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?


No, but a collection of boost::any's might do the job. http://www.boost.org

It's possible, but you have to keep track somehow of the actual types of the
objects in the collection, or you can't get them back.
It really depends on what operations the OP needs to be able to perform on the
elements of the collection.
Jonathan
.

User: "Rene Moehring"

Title: Re: Container for different types of variables 08 Dec 2004 02:00:42 AM
On Sun, 05 Dec 2004 17:32:02 +0000, Mathew Hendry wrote:

On 5 Dec 2004 08:55:46 -0800,

(m@j3R ;) wrote:

I need to use sth. like container for different types of variables.
Is sth like this in c++ STL?


No, but a collection of boost::any's might do the job. http://www.boost.org

Or boost::variant.
--
I'm not a racist. I hate everyone equally!
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER