473,587 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi,

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

|padsol15 141make 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<typena me 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_dat a) { /* void */ }
~wrapper() { /* void */ }

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

};
Jun 27 '08 #1
3 2750
found a solution here (happens always after posting :-):

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

\Frank
Jun 27 '08 #2

"Frank Bergemann" <FB********@web .dewrote in message
news:49******** *************** ***********@f36 g2000hsa.google groups.com...
Hi,

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

|padsol15 141make 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<typena me X>
class _common
{
public:
typedef X ForType;
typedef X::BaseType BaseType;
^^^
<...>
try:

typedef typename X::BaseType BaseType;

regards
Andy Little


Jun 27 '08 #3
On 2 Maj, 11:42, Frank Bergemann <FBergem...@web .dewrote:
Hi,

the (gcc-3.4.4) compiler complains, if i try to use a typedef of
subclass in superclass:
[SNIP]
template<typena me 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
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3445
by: Mike Smith | last post by:
Sorry about the multiple post, but I just realized my prior post was in a thread that dates back a couple of days, so people might not see it. Which is considered better for writing interfaces in C++: abstract base classes, or templates - and why? I.e. when is one preferable over the other? Let's suppose, just by way of an example, that...
2
1807
by: fabioppp | last post by:
Is this piece of code correct? template<typename Child> struct Base { enum { derived_id = Child::id }; // <= wont compile! void invokeDispatch() { ((Child*) this)->invoke(); // <= this compile fine!
8
6705
by: sugaray | last post by:
hi, i wrote a simple base-conveter utility for practice, it seems works fine right now, hope any gurus out there can give me some suggestions to, critics of, optimisations on this program or my programming practice. the code are mainly written in C, but need to be compiled using a C++ compiler because of the using of builtin Boolean type. it...
30
4225
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
8
2267
by: SL | last post by:
I try to validate against a schema a document stored in several files thanks to external entities. The parseur add a 'xml:base="url"' attribute on the root element of this sub-trees during parsing, so the validation of the document fails. Is there a recommanded solution to this situation ? I have no idea how to handle the problem: I don't...
2
2226
by: Philipp Tietjen | last post by:
I have a serious problem, trying to call a C written .dll function in my c# program! The problem is I only have the already compiled .dll file and cannot look into the code. I have no problems calling all functions that are listed in the .dll, that works just fine... except this one: The function headers goes like this: bool...
6
2503
by: Noah Roberts | last post by:
This isn't possible? template < typename SUB > struct Base { typedef typename SUB::dim dimen; }; struct Sub : Base<Sub> {
11
2689
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h> #include <string.h> #define LENGTH 20 int temp, m, n, i, r, base10, true;
5
4015
by: jyck91 | last post by:
please~help me to write a program to convert the baseN(2-9) to base10 eg. 101(2)----->5(10) 1211(3)------->X(10) ...... P.S. i am really misunderstand the C programming, plz write the simple statments as you can
18
2445
by: Stephan Beal | last post by:
Hi, all! Before i ask my question, i want to clarify that my question is not about the code i will show, but about what the C Standard says should happen. A week or so ago it occurred to me that one can implement a very basic form of subclassing in C (the gurus certainly already know this, but it was news to me). What i've done (shown...
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.