Questions about injected-class-name for template

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Following test case compile failed with GCC 4.6, the error message:

/data/a.cpp: In constructor 'D<T>::D(bool)':
/data/a.cpp:19:6: error: class 'D<T>' does not have any field named 'B'
/data/a.cpp: In constructor 'D<T>::D(bool) [with T = A]':
/data/a.cpp:24:15:   instantiated from here
/data/a.cpp:19:9: error: no matching function for call to 'B<A>::B()'
/data/a.cpp:19:9: note: candidates are:
/data/a.cpp:6:4: note: B<T>::B(bool) [with T = A]
/data/a.cpp:6:4: note:   candidate expects 1 argument, 0 provided
/data/a.cpp:4:27: note: B<A>::B(const B<A>&)
/data/a.cpp:4:27: note:   candidate expects 1 argument, 0 provided

It seems that, gcc failed to lookup injected name B in "template
<class T> D<T>::D(bool s) : B(s)".

14.6.1/p3,
The injected-class-name of a class template or class template
specialization can be used either as a templatename
or a type-name wherever it is in scope. [ Example:
template <class T> struct Base {
Base* p;
};
template <class T> struct Derived: public Base<T> {
typename Derived::Base* p; // meaning Derived::Base<T>
};

The injected name "B" here equal to "B<T>", which should compile clean.

class A{};

template <class T> struct B
{
   B(bool s){}
};

template <class T> class D: public B<T>
{
public:
   D(bool s);
};

template <class T>
D<T>::D(bool s)
   : B(s)
   {
   }

D<A> library(0);


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux