Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > CRTP base class using typedef of sub-class doesn't work

Reply
Thread Tools

CRTP base class using typedef of sub-class doesn't work

 
 
Frank Bergemann
Guest
Posts: n/a
 
      05-02-2008
Hi,

the (gcc-3.4.4) compiler complains, if i try to use a typedef of
subclass in superclass:

|padsol15 141> make Helper_test
[CXXD] Helper_test.cc
In file included from Helper_test.cc:17:
Helper.h:258: error: ISO C++ forbids declaration of `BaseType' with no
type
Helper.h:258: error: `::BaseType' is not a valid declarator
Helper.h:258: error: expected `;' before "BaseType"
make: *** [Helper_test.o] Error 1

???


*
* internal base type for shared basics
*/
template<typename X>
class _common
{
public:
typedef X ForType;
typedef X::BaseType BaseType;
typedef _common Super;

BaseType m_data;
/*
operators based on STL predicator specializations of BaseType,
etc, ...
*/
} ;

class wrapper : public _common<wrapper>
{
public:
typedef wrapped_t BaseType; // _common<> can't use that?!

wrapper (wrapped_t data) : Super(data) { /* void */ }
wrapper (wrapper const& rhs) : Super(rhs.m_data) { /* void */ }
~wrapper() { /* void */ }

wrapper& operator=(wrapper const& rhs)
{
if (&rhs != this) {
wrapper x(rhs);
Super::swap(x);
}
return *this;
}

};


 
Reply With Quote
 
 
 
 
Frank Bergemann
Guest
Posts: n/a
 
      05-02-2008
found a solution here (happens always after posting :

http://groups.google.de/group/comp.l...886cdc72de4649

\Frank
 
Reply With Quote
 
 
 
 
kwikius
Guest
Posts: n/a
 
      05-02-2008

"Frank Bergemann" <> wrote in message
news:4963ef62-746a-465b-a314-...
> Hi,
>
> the (gcc-3.4.4) compiler complains, if i try to use a typedef of
> subclass in superclass:
>
> |padsol15 141> make Helper_test
> [CXXD] Helper_test.cc
> In file included from Helper_test.cc:17:
> Helper.h:258: error: ISO C++ forbids declaration of `BaseType' with no
> type
> Helper.h:258: error: `::BaseType' is not a valid declarator
> Helper.h:258: error: expected `;' before "BaseType"
> make: *** [Helper_test.o] Error 1


<...>

> * internal base type for shared basics
> */
> template<typename X>
> class _common
> {
> public:
> typedef X ForType;
> typedef X::BaseType BaseType;


^^^
<...>
try:

typedef typename X::BaseType BaseType;

regards
Andy Little




 
Reply With Quote
 
peter koch
Guest
Posts: n/a
 
      05-02-2008
On 2 Maj, 11:42, Frank Bergemann <FBergem...@web.de> wrote:
> Hi,
>
> the (gcc-3.4.4) compiler complains, if i try to use a typedef of
> subclass in superclass:
>

[SNIP]
> template<typename X>
> class _common
> {
> public:
> * * * * typedef X ForType;
> * * * * typedef X::BaseType BaseType;


[snip]

As others already pointed out, this is because the compiler can't
detect that X::BaseType is a type: remember the typename keyword.
Perhaps your question should be dubbed Curiously Recurring Template
Question?

/Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Base class method Need base class value Karan Rajput Ruby 2 12-22-2010 04:47 PM
CRTP nullary in derived conflicts with unary in base er ci C++ 1 07-24-2010 08:47 PM
base class public type (non template and template base class) Hicham Mouline C++ 1 04-20-2009 03:28 PM
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
Access of base class' private base class: qualification required, why Alf P. Steinbach C++ 6 09-03-2005 04:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57