public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Questions about injected-class-name for template
@ 2011-05-12  3:45 zhang qingshan
  0 siblings, 0 replies; only message in thread
From: zhang qingshan @ 2011-05-12  3:45 UTC (permalink / raw)
  To: gcc-help

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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-12  3:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-12  3:45 Questions about injected-class-name for template zhang qingshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).