我有以下代碼。爲什麼不能從初始化列表初始化我的類,即使它從std :: list派生?
#include <utility>
#include <list>
#include <iostream>
class Pair: public std::pair<unsigned int, unsigned int>{
Pair (unsigned int h, unsigned int l) : pair(h,l){};
};
class PairList: public std::list<Pair>{};
int main(int argc, char** argv){
PairList pl = {{800,400},{800,400}};
}
予編譯它使用V4.6的MinGW的克++用命令行
g++ -std=c++0x Test.cpp -o test.exe
和得到了錯誤:
error: could not convert '{{800, 400}, {800, 400}}' from '<brace-enclosed initializer list>' to 'PairList'
但是,如果在main()我寫
list<pair<unsigned int,unsigned int>> pl = {{800,400},{800,400}};
所有工作正常。
WTF?
@ExplodingRat當編輯一個不好的標題時,它對簡單修復小的錯別字沒有多大幫助。建議編寫一個有意義的標題,而不要用完美的拼寫來獲得毫無價值的標題。 –