Unskilled search and (possibly) dependent base classes

Consider the following program:

template <typename T> struct t { struct base { void f1(); }; struct derived : base { void f2() { f1(); } }; }; 

In derived::f2 , an unqualified search is used to search f1 . Will there be a base search? Will base::f1 be found? Is base dependent type?

Please confirm your answers with quotation marks from the standard.

+4
source share
2 answers

Yes, base dependent, so f1 not found. In C ++ 03, this was cleaned up by adding 14.6.1/2d (which was not in C ++ 98) and in C ++ 0x it was explicitly stated on 14.6.2.1/6 (n3126).

Dependence is important because the following are possible:

 // for T = int, f1 does not exist. template<> struct t<int>::base { }; 
+7
source

This does not fit in the comment field ...

gcc rejects the code:

there are no arguments to 'f1' that depend on a template parameter, so a declaration of 'f1' must be available .

However, introducing this-> to f1 makes it dependent, and then compilation works.

As for my experience, the same behavior applies to:

  • (you need to typedef them again)
  • (you need to use using base::f1 or this->f1 )

And I saw this behavior in:

  • gcc 3.4
  • VC ++ 9
  • VC ++ 10

And now we can wait for standardists to get accurate quotes from the standard.

0
source

All Articles