473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

};
Jun 27 '08 #1
3 2733
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**********************************@f36g2000 hsa.googlegroups.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<typename 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<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
Jun 27 '08 #4

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

Similar topics

7
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...
2
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...
8
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...
30
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
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,...
2
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...
6
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
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>...
5
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...
18
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...

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.