Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   std::map<std::string,int> Problem (http://www.velocityreviews.com/forums/t951326-std-map-std-string-int-problem.html)

tombert 08-24-2012 01:21 PM

std::map<std::string,int> Problem
 
Hi all,

can someone please tell me what's wrong with that code?
I am using gcc 4.7 from MinGW, under 4.6 it seemed to have compiled correctly.

The error is:
: error: no matching function for call to 'std::map<std::basic_string<char>, int>::insert(std::string&, int)'

Example:
class TDir {
typedef std::map<std::string,int> Subdirs;
public:
TDir(){}
~TDir(){}
void getDir(std::string name) {
Subdirs t;
t.insert(name,0);
}
};

Öö Tiib 08-24-2012 01:28 PM

Re: std::map<std::string,int> Problem
 
On Friday, August 24, 2012 4:21:29 PM UTC+3, tombert wrote:
> Hi all,
>
>
>
> can someone please tell me what's wrong with that code?
>
> I am using gcc 4.7 from MinGW, under 4.6 it seemed to have compiled correctly.
>
>
>
> The error is:
>
> : error: no matching function for call to 'std::map<std::basic_string<char>, int>::insert(std::string&, int)'
>
>
>
> Example:
>
> class TDir {
>
> typedef std::map<std::string,int> Subdirs;
>
> public:
>
> TDir(){}
>
> ~TDir(){}
>
> void getDir(std::string name) {
>
> Subdirs t;
>
> t.insert(name,0);


Should be:

t.insert( std::pair<std::string,int>(name,0) );
>
> }
>
> };



Luca Risolia 08-24-2012 02:14 PM

Re: std::map<std::string,int> Problem
 
On 24/08/2012 15:21, tombert wrote:
> Hi all,
>
> can someone please tell me what's wrong with that code?
> I am using gcc 4.7 from MinGW, under 4.6 it seemed to have compiled correctly.
>
> The error is:
> : error: no matching function for call to 'std::map<std::basic_string<char>, int>::insert(std::string&, int)'


> class TDir {
> typedef std::map<std::string,int> Subdirs;
> public:
> TDir(){}
> ~TDir(){}
> void getDir(std::string name) {
> Subdirs t;
> t.insert(name,0);

^^^^^^

It's strange gcc4.6 compiled that code.

try with std::make_pair from <utility>:
t.insert(std::make_pair(name,0));


Juha Nieminen 08-25-2012 03:51 PM

Re: std::map<std::string,int> Problem
 
Öö Tiib <ootiib@hot.ee> wrote:
> t.insert( std::pair<std::string,int>(name,0) );


How about just

t.insert( std::make_pair(name,0) );

Or even easier:

t[name] = 0;


All times are GMT. The time now is 06:50 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.