473,397 Members | 2,056 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,397 software developers and data experts.

Storing objects in map class

22
Hi,
I've these classes

Integer derived from Object
String derived from Object

I'm creating another class MyMap
which shall have the capability to store Integer, String (or any other obj derived from 'Object' class) objects in it. MyMap has a data member of stl map.

Can u plz give me a tiny program showing how to store Integer/String objs in MyMap. MyMap is not inherited from anything, it just use stl map as data member. providing an interface to other classes for manipulating stl map easily.

I'm getting into lot of trouble doing this, please help.
Sep 19 '07 #1
4 5195
gpraghuram
1,275 Expert 1GB
Hi,
I've these classes

Integer derived from Object
String derived from Object

I'm creating another class MyMap
which shall have the capability to store Integer, String (or any other obj derived from 'Object' class) objects in it. MyMap has a data member of stl map.

Can u plz give me a tiny program showing how to store Integer/String objs in MyMap. MyMap is not inherited from anything, it just use stl map as data member. providing an interface to other classes for manipulating stl map easily.

I'm getting into lot of trouble doing this, please help.
Check this
Expand|Select|Wrap|Line Numbers
  1. map<int,string> int_string_map;
  2. string s1("abc");
  3. int_string_map[1]=s1;
  4. int_string_map[2]=s1;
  5.  
  6.  
  7.  
Hopw this is what u need

Thanks
Raghuram
Sep 19 '07 #2
jeet232
22
Check this
Expand|Select|Wrap|Line Numbers
  1. map<int,string> int_string_map;
  2. string s1("abc");
  3. int_string_map[1]=s1;
  4. int_string_map[2]=s1;
  5.  
  6.  
  7.  
Hopw this is what u need

Thanks
Raghuram
Hi Raghuram,
thanks for reply, but can u pls tell me how the 'get' functionality will be achieved. like say:

Expand|Select|Wrap|Line Numbers
  1. map<string,string> str_string_map;
  2. string s1("abc");
  3.  
Then in this case, how the insertion & retreival will work?
Sep 19 '07 #3
gpraghuram
1,275 Expert 1GB
Hi Raghuram,
thanks for reply, but can u pls tell me how the 'get' functionality will be achieved. like say:

Expand|Select|Wrap|Line Numbers
  1. map<string,string> str_string_map;
  2. string s1("abc");
  3.  
Then in this case, how the insertion & retreival will work?
HI,
Read this Map tutorial to get a good idea about the map.
Thanks
Raghuram
Sep 20 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
[quote=jeet232]
I've these classes

Integer derived from Object
String derived from Object
[/code]

You have your solution here. MyMap must contain Objects. Plus a key. More to the point, a handle to an Object plus a key:
Expand|Select|Wrap|Line Numbers
  1. map<int, Handle<Object> > MyMap;
  2.  
1) Read the article on Handle classes.
2) Read the article on Visitor. You will need a Visitor to access specific methods in your derived classes that are not in tyour base class.
3) Your entire application must use Handle<Object>.
4) Get a design patterns book. Look up Template Method. You will need this too.
Sep 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: tuvok | last post by:
How can objects of different types be stored in a collection? For example: struct S1 { /*...*/ }; struct S2 { /*...*/ }; struct Sn { /*...*/ }; template<typename T> class X { public:
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
10
by: Diego F. | last post by:
Hello. I need to store custom objects in a SQL Server 2000 table. Which is the easiest way to do it? Do I need to write methods to store each attribute separately from C# app to the table and the...
1
by: Martin Widmer | last post by:
Hi guys I am wondering what is a proper way to persistently store objects into SQL-Server. I see four possible ways: 1.) Serialize to XML and then store the XML in the SQL server 2.) Write a...
10
by: Mark Rae | last post by:
Hi, This relates to the previous thread "Disappearing Sessions", but is a bit more generic so I thought I'd start a new thread. This one relates to the storing of objects in Session once only to...
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
3
by: Ramon F Herrera | last post by:
Newbie alert: I come from C programming, so I still have that frame of mind, but I am trying to "Think in C++". In C this problem would be solved using unions. Hello: Please consider the...
3
by: mk | last post by:
Hello everyone, I'm storing functions in a dictionary (this is basically for cooking up my own fancy schmancy callback scheme, mainly for learning purpose): .... return "f2 " + arg .......
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?
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:
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.