barton4
24-03-2010, 21:01
Hallo,
im folgenden Code soll der Constructor von A ein default Parameter erhalten. Leider spuckt der g++ ein haufen fehlermeldung aus mit dennen ich nichts anfangen kann.
- Interessanterweise meckert er bei einem vector mit Defaultparameter nicht!
- unter Visual Studio 2008 funktiert der code
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
class A
{
public:
A(map<int,int> number = map<int,int>())
{
}
};
int main()
{
A a;
}
main.cpp:11: error: expected ‘,’ or ‘...’ before ‘>’ token
main.cpp:11: error: wrong number of template arguments (1, should be 4)
/usr/include/c++/4.3/bits/stl_map.h:91: error: provided for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
main.cpp:11: error: default argument missing for parameter 2 of ‘A::A(std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >, int)’
main.cpp: In function ‘int main()’:
main.cpp:11: error: ‘A::A(std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >, int)’ is private
main.cpp:19: error: within this context
im folgenden Code soll der Constructor von A ein default Parameter erhalten. Leider spuckt der g++ ein haufen fehlermeldung aus mit dennen ich nichts anfangen kann.
- Interessanterweise meckert er bei einem vector mit Defaultparameter nicht!
- unter Visual Studio 2008 funktiert der code
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
class A
{
public:
A(map<int,int> number = map<int,int>())
{
}
};
int main()
{
A a;
}
main.cpp:11: error: expected ‘,’ or ‘...’ before ‘>’ token
main.cpp:11: error: wrong number of template arguments (1, should be 4)
/usr/include/c++/4.3/bits/stl_map.h:91: error: provided for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
main.cpp:11: error: default argument missing for parameter 2 of ‘A::A(std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >, int)’
main.cpp: In function ‘int main()’:
main.cpp:11: error: ‘A::A(std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >, int)’ is private
main.cpp:19: error: within this context