inserting class objects into maps

  • Follow


I know this is a simple question, so any help would be very much appreciated.

How do i insert a class into my map object along with a string as a key?

here is bit of my code.(Team is my class name)
///////////////////////////////////

Team myTeam();

map<string, Team> teams;

teams["teams"] = team;
/////////////////////////////

This returns a compile error.. how can i insert my class object into the map,
I tried using the pair<class T1, class T2> class, but my first argument is
a string not a class. therefore i can't use the insert() method from map.
thanx people

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply kichtr 9/13/2003 8:06:41 PM

"Kieth" <kichtr@linuxmail.org> wrote in message
news:8c929d22.0309130751.4844d3a@posting.google.com...
> I know this is a simple question, so any help would be very
> much appreciated.

We can help you the most when you provide enough info to
understand your problem.

> How do i insert a class into my map object along with a
> string as a key?
>
> here is bit of my code.(Team is my class name)
> ///////////////////////////////////
>
> Team myTeam();
>
> map<string, Team> teams;
>
> teams["teams"] = team;
> /////////////////////////////

This could be the correct way to do it given a suitable
defintion of 'Team' and 'team'.  But you don't give either,
so it's hard to say what the problem is.

> This returns a compile error..

*What* compile error?

> how can i insert my class object into the map, I tried using
> the pair<class T1, class T2> class, but my first argument is
> a string not a class.

The term 'class' when used as a template argument is a bit
of a misnomer, since it can match any non-template type.

> therefore i can't use the insert() method from map.

You can, but you need to provide more information before
anyone can show you how.

Dave



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply David 9/14/2003 1:36:34 AM


Kieth wrote:
> I know this is a simple question, so any help would be very much
> appreciated.
>
> How do i insert a class into my map object along with a string as a
> key?
>
> here is bit of my code.(Team is my class name)
> ///////////////////////////////////
>
> Team myTeam();

Declares a function named myTeam, which returns a Team object and takes not
arguments.

>
> map<string, Team> teams;

I suppose string is std::string.

> teams["teams"] = team;

Where is "team" coming from???  It is not defined anywhere.

> This returns a compile error.. how can i insert my class object into
> the map, I tried using the pair<class T1, class T2> class, but my
> first argument is
> a string not a class. therefore i can't use the insert() method from
> map. thanx people

Please post the *smallest* but still *complete* code which shows your
problem.  The above code snippets show way too little and already way too
many (possible) errors.

-- 
WW aka Attila



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply White 9/14/2003 1:41:55 AM

2 Replies
517 Views

(page loaded in 0.017 seconds)

Similiar Articles:













7/29/2012 4:22:02 PM


Reply: