檢查this答案後,我仍然似乎並沒有解決我的問題:迭代器複製構造函數錯誤,如右側'非法'。運營商
我現在有一個test_iterator
結構,這將包裹不同類型的迭代器標籤到它讓我使用所有類型的迭代測試功能。當爲這個迭代器創建一個拷貝構造函數時,我的問題就出現了。當前的結構被定義爲
template <typename BaseIterator, typename IteratorTag>
struct test_iterator
: boost::iterator_adaptor<
test_iterator<BaseIterator, IteratorTag>,
BaseIterator, boost::use_default, IteratorTag>
{
private:
typedef boost::iterator_adaptor<
test_iterator<BaseIterator, IteratorTag>,
BaseIterator, boost::use_default, IteratorTag>
base_type;
public:
test_iterator() : base_type() {}
test_iterator(BaseIterator base) : base_type(base) {};
test_iterator(const test_iterator& cpy):
base_type(cpy.base_type) {};
};
最後一個構造函數(拷貝構造函數)是給我找麻煩,我似乎無法掌握我在做什麼錯。我收到確切的錯誤是
error C2274: 'function-style cast' : illegal as right side of '.' operator
這是這一行:
base_type(cpy.base_type) {};
你在測試函數或迭代器中的代碼嗎? –
您沒有接受函數對象的構造函數。你確定你不是指base_type(cpy.base_type())嗎? – stix
讓編譯器隱式地定義複製構造函數(以及移動構造函數,析構函數和複製/移動賦值)。 – Casey