[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
std::map as a default arg to a member function/constructor
From: |
szymonwlodarski |
Subject: |
std::map as a default arg to a member function/constructor |
Date: |
Fri, 13 Feb 2009 12:35:37 -0800 (PST) |
User-agent: |
G2/1.0 |
I have encountered a bug (I think). When I compile this (g++ 4.2.3):
#include <map>
struct A
{
std::map< int, int > m;
A( std::map< int, int > m1 = std::map< int, int >())
: m( m1 )
{
}
};
int
main()
{
}
I get:
../main.cpp:14: error: expected ‘,’ or ‘...’ before ‘>’ token
../main.cpp:14: error: wrong number of template arguments (1, should
be 4)
/usr/include/c++/4.2/bits/stl_map.h:93: error: provided for
‘template<class _Key, class _Tp, class _Compare, class _Alloc> class
std::map’
../main.cpp:14: error: default argument missing for parameter 2 of
‘B::B(std::map<int, int, std::less<int>,
std::allocator<std::pair<const int, int> > >, int)’
It works with VC++, Comeau Online does not complain either.
If I change A to:
struct A
{
typedef std::map< int, int > T;
T m;
A( T m1 = T())
: m( m1 )
{
}
};
Now it works fine.
There is no problem with non-member functions.
void
fun( std::map< int, int > m1 = std::map< int, int >())
{
}
OK.
--
Szymon
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- std::map as a default arg to a member function/constructor,
szymonwlodarski <=