簡體   English   中英

類中的Typedef

[英]Typedef in class

有這樣的代碼:

template <class T>
class SomeClass{
    typedef boost::shared_ptr<T> sPtr;
    typedef std::vector<sPtr> c;
    typedef c::iterator cIt;  // here is the problem
};

而錯誤是:

main.cpp:23: error: type ‘std::vector<boost::shared_ptr<X>, std::allocator<boost::shared_ptr<X> > >’ is not derived from type ‘SomeClass<T>’
main.cpp:23: error: expected ‘;’ before ‘cIt’

如何在類中使用typedef模板化參數?

編輯:

我想通了,因為g ++必須是:

typedef typename c::iterator cIt;  // here is the problem

請關閉它。

問題是c::iterator是一個qualified-idc的類型取決於模板參數。 根據§14.6/3

qualified-id旨在引用不是當前實例化成員的類型且其嵌套名稱說明符引用依賴類型時,它應以關鍵字typename作為前綴...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM