 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
infested Guest
|
Posted: Sun Feb 05, 2006 2:00 am Post subject: CRTP and inner-classes |
|
|
template <typename C>
class A : public B< A<C> > {
class A1;
class A2;
};
template <typename D>
class B {
typedef typename D::A1 B1;
}
I'm using mingw g++ 3.2.3
compiler error is something like that: no type named A1 in class A<C>
I'm not sure if it is possible to compile such code, but it would be
great:). I know that I can write a baseclass for these classes to omit
crtp, but is it necessary?
Thanks in advance
--
Greetings,
Łukasz
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Sun Feb 05, 2006 2:00 pm Post subject: Re: CRTP and inner-classes |
|
|
* infested:
| Quote: | template <typename C
class A : public B< A<C> > {
class A1;
class A2;
};
template <typename D
class B {
typedef typename D::A1 B1;
}
I'm using mingw g++ 3.2.3
compiler error is something like that: no type named A1 in class A<C
|
Please, in future post accurate code -- and error messages.
However, it's not difficult to see what you mean in this case, although
the code lacks a forward declaration of B, lacks "public:" in class A,
and lacks a semicolon at the end of B.
| Quote: | I'm not sure if it is possible to compile such code, but it would be
great:).
|
The problem seems to be that at the time the class level typedef in B is
checked (what's the word here?), class A is still an incomplete type.
Inside a member function in class B the typedef works fine. Because
member definitions, as opposed to their declarations, are instantiated
later, if they are instantiated.
| Quote: | I know that I can write a baseclass for these classes to omit
crtp, but is it necessary?
|
I don't understand what you mean by "to omit crtp", because if crtp
(curiously recurring template pattern, the inheritance above) is needed
then you can't just omit it.
However you can use a base class of A to introduce the types A1 and A2.
Or you can define A1 and A2 separately and pass them as template
arguments up to B, to keep the control in class A.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|