[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:17:02
Message-ID: CALuKrvBRz348BE_1FoCEe-GSREESf9AMi+FNmGecW13ENsNALA () 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)]
<div dir="ltr">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.<div>The codes like \
follows (also in attachment):</div><div>================================================</div>
<div><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 \
class="Apple-tab-span" style="white-space:pre"> </span>typedef \
std::map<std::string,std::string> MapKeyValue_t;</div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span>void PrintMap(const \
MapKeyValue_t &my_map </div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span>= MapKeyValue_t())</div><div>#else</div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span>void PrintMap(const \
std::map<std::string,std::string> &my_map </div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span>= \
std::map<std::string,std::string>())</div> \
<div>#endif</div><div>{</div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span>std::map<std::string,std::string>::const_iterator \
it;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for (it = \
my_map.begin(); it != my_map.end(); it++)</div> <div><span class="Apple-tab-span" \
style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span>std::cout << it->first << " \
" << it->second << std::endl;</div> <div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span>}</div><div>}</div><div>};</div><div><br></div><div>int \
main()</div><div>{</div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span>A a;</div> <div><span class="Apple-tab-span" \
style="white-space:pre"> </span>a.PrintMap();</div><div><span class="Apple-tab-span" \
style="white-space:pre"> </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></div>
--047d7b6251b0b03b5a04e3945a8e--
["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