2014-08-27 50 views
3

我注意到一些情況下,std :: pair會隱式轉換爲不帶警告的不同類型的std :: pair,但我找不出原因。我查看了std :: pair的構造函數,但無法弄清楚。有人可以向我解釋這個嗎?爲什麼允許從<int64_t,int64_t>到<int,int>對的隱式轉換?

實施例:

std::pair<int,int> a = std::pair<int64_t, int64_t>(1,2); 

給出與鐺-Wall -Weverything沒有警告。

+3

它是http://stackoverflow.com/questions/25535106/no-warning-on-implicit-conversion的重複? – Slava 2014-08-27 19:21:26

+0

只需閱讀參考資料http://www.cplusplus.com/reference/utility/pair/operator=/ – 2014-08-27 19:23:41

回答

2

構造

template<class U, class V> pair(const pair<U, V>& p); 

允許從任何對複製提供的p第一元件可以被轉換爲被構造對第一元件,與同爲第二元件。

相關問題