如下頭可與當我調用該函數蝙蝠不帶參數如預期中的註釋部分:的默認容器參數
class Test
{
public:
void bat(std::vector<int> k = std::vector<int>()) {}
//void cat(std::map<int, std::vector<int> > k = std::map<int, std::vector<int> >()) {}
};
但是當我嘗試使用在頭貓功能:
class Test
{
public:
void bat(std::vector<int> k = std::vector<int>()) {}
void cat(std::map<int, std::vector<int> > k = std::map<int, std::vector<int> >()) {}
};
我得到:
test.h:14: error: expected ',' or '...' before '>' token
test.h:14: error: wrong number of template arguments (1, should be 4)
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h:92: error: provided for 'template<class _Key, class _Tp, class _Compare,\
class _Alloc> class std::map'
test.h:14: error: default argument missing for parameter 2 of 'void Test::cat(std::map<int, std::vector<int, std::allocator<int> >, std::less<int>, std::all\
ocator<std::pair<const int, std::vector<int, std::allocator<int> > > > >, std::vector<int, std::allocator<int> >)'
怎麼來的?有沒有簡單的解決方法呢?希望不需要在界面中改變指針類型?
這是我的完整標題:
#ifndef TEST_H
#define TEST_H
#include <map>
#include <vector>
#include <sstream>
#include <iostream>
class Test
{
public:
//void bat(std::vector<int> k = std::vector<int>()) {}
void cat(std::map<int, std::vector<int> > k = std::map<int, std::vector<int> >()) {}
};
#endif
因此,所有的權利,包括在那裏。我的海灣合作委員會版本過時了(不在家,在家裏也不行) - 但在工作中它是4.1.2
聞起來像一個GCC的bug - [失敗4.3.4](http://ideone.com/alZRI),[適用於4.5.1](http://ideone.com/6Ppze)。你使用什麼版本? – ildjarn
這個編譯好,你包括'
錯誤信息將指向4.1.2,包含'