添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

GCC reports the following errors:

test.cpp:8: error: type 'std::vector<A<T>*, std::allocator<A<T>*> >' is not derived from type 'A<T>'
test.cpp:8: error: expected ';' before 'begin'
test.cpp:12: error: expected `;' before 'private'

What is wrong? How to fix it?

In this line, you are missing the typename keyword:

std::vector<A<T> *>::const_iterator begin(){

You need:

typename std::vector<A<T> *>::const_iterator begin(){

This because std::vector<A<T> *> is dependent on the template parameter (T) of the class template (A). To enable correct parsing of the template without having to make any assumptions about possible specializations of any other templates, the language rules require you to indicate which dependent names denote types by using the typename keyword.

You need to add typename as the types depend on each other and the compiler can't figure out if it really is a type.

However, on gcc 4.5.0 i get a more concise error message:

test.cc:8:3: error: need ‘typename’ before ‘std::vector<A<T>*>::const_iterator’ because ‘std::vector<A<T>*>’ is a dependent scope

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.