Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

std::map as a default arg to a member function/constructor

24 views
Skip to first unread message

szymonw...@gmail.com

unread,
Feb 13, 2009, 3:35:37 PM2/13/09
to
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

0 new messages