[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-dev
Subject: [cfe-dev] how to pass stdmap as a default constructor parameter
From: Jean Lee <xiaoyur347 () gmail ! com>
Date: 2013-08-10 9:27:01
Message-ID: CALuKrvDgfojCEMyhpVTGuKcr0ps4OCeqERVj0srWuWqJN2enWA () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I suffer a problem when using std::map in clang. I compile it in clang 3.3
under ubuntu 12.04, and the problem is also in clang 3.0.
The codes like follows (also in attachment):
================================================
#include <iostream>
#include <map>
#include <string>
class A
{
public:
#if 0
typedef std::map<std::string,std::string> MapKeyValue_t;
void PrintMap(const MapKeyValue_t &my_map
= MapKeyValue_t())
#else
void PrintMap(const std::map<std::string,std::string> &my_map
= std::map<std::string,std::string>())
#endif
{
std::map<std::string,std::string>::const_iterator it;
for (it = my_map.begin(); it != my_map.end(); it++)
{
std::cout << it->first << " " << it->second << std::endl;
}
}
};
int main()
{
A a;
a.PrintMap();
return 0;
}
====================================================
The output is :
test.cpp:9:36: error: expected ')'
= std::map<std::string,std::string>())
^
test.cpp:8:14: note: to match this '('
void PrintMap(const std::map<std::string,std::string> &my_map
^
test.cpp:9:24: error: expected '>'
= std::map<std::string,std::string>())
^
test.cpp:22:13: error: too few arguments to function call, expected 2, have
0
a.PrintMap();
~~~~~~~~~~ ^
test.cpp:8:1: note: 'PrintMap' declared here
void PrintMap(const std::map<std::string,std::string> &my_map
^
3 errors generated.
=========================================================
It compiles ok if I write this way:
typedef std::map<std::string, std::string> MapKeyValue_t;
void PrintMap(const MapKeyValue_t &my_map
= MapKeyValue_t())
Both compile ok under g++.
[Attachment #5 (text/html)]
<span style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">I \
suffer a problem when using std::map in clang. I compile it in clang 3.3 under ubuntu \
12.04, and the problem is also in clang 3.0.</span><div \
style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">
The codes like follows (also in attachment):</div><div \
style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">================================================</div><div \
style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">
<div><div>#include <iostream></div><div>#include <map></div><div>#include \
<string></div><div><br></div><div>class \
A</div><div>{</div><div>public:</div><div>#if 0</div><div><span \
style="white-space:pre-wrap"> </span>typedef std::map<std::string,std::string> \
MapKeyValue_t;</div>
<div><span style="white-space:pre-wrap"> </span>void PrintMap(const MapKeyValue_t \
&my_map </div><div><span style="white-space:pre-wrap"> </span>= \
MapKeyValue_t())</div><div>#else</div><div><span \
style="white-space:pre-wrap"> </span>void PrintMap(const \
std::map<std::string,std::string> &my_map </div>
<div><span style="white-space:pre-wrap"> </span>= \
std::map<std::string,std::string>())</div><div>#endif</div><div>{</div><div><span \
style="white-space:pre-wrap"> </span>std::map<std::string,std::string>::const_iterator \
it;</div>
<div><span style="white-space:pre-wrap"> </span>for (it = my_map.begin(); it != \
my_map.end(); it++)</div><div><span \
style="white-space:pre-wrap"> </span>{</div><div><span \
style="white-space:pre-wrap"> </span>std::cout << it->first << " \
" << it->second << std::endl;</div>
<div><span style="white-space:pre-wrap"> </span>}</div><div>}</div><div>};</div><div><br></div><div>int \
main()</div><div>{</div><div><span style="white-space:pre-wrap"> </span>A \
a;</div><div><span style="white-space:pre-wrap"> </span>a.PrintMap();</div>
<div><span style="white-space:pre-wrap"> </span>return \
0;</div><div>}</div></div><div>====================================================</div><div>The \
output is :</div><div><div>test.cpp:9:36: error: expected ')'</div>
<div> = std::map<std::string,std::string>())</div><div> \
^</div><div>test.cpp:8:14: note: to match this '('</div><div>void \
PrintMap(const std::map<std::string,std::string> &my_map </div>
<div> ^</div><div>test.cpp:9:24: error: expected \
'>'</div><div> = \
std::map<std::string,std::string>())</div><div> \
^</div><div>test.cpp:22:13: error: too few arguments to function call, expected 2, \
have 0</div>
<div> a.PrintMap();</div><div> ~~~~~~~~~~ ^</div><div>test.cpp:8:1: \
note: 'PrintMap' declared here</div><div>void PrintMap(const \
std::map<std::string,std::string> &my_map </div><div>^</div>
<div>3 errors generated.</div><div><br></div><div>=========================================================</div><div>It \
compiles ok if I write this way:</div><div>typedef std::map<std::string, \
std::string> MapKeyValue_t;<br>
</div><div><div>void PrintMap(const MapKeyValue_t &my_map </div><div><span \
style="white-space:pre-wrap"> </span>= MapKeyValue_t())</div><div><br></div><div>Both \
compile ok under g++.</div></div></div></div>
--001a11c22a0256597004e3947e2d--
["test.cpp" (text/x-c++src)]
#include <iostream>
#include <map>
#include <string>
class A
{
public:
#if 0
typedef std::map<std::string,std::string> MapKeyValue_t;
void PrintMap(const MapKeyValue_t &my_map
= MapKeyValue_t())
#else
void PrintMap(const std::map<std::string,std::string> &my_map
= std::map<std::string,std::string>())
#endif
{
std::map<std::string,std::string>::const_iterator it;
for (it = my_map.begin(); it != my_map.end(); it++)
{
std::cout << it->first << " " << it->second << std::endl;
}
}
};
int main()
{
A a;
a.PrintMap();
return 0;
}
_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic