Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > CRTP question

Reply
Thread Tools

CRTP question

 
 
fabioppp
Guest
Posts: n/a
 
      04-15-2005
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!
}
};

struct Derived1 : public Base<Type1>
{
enum { id = 1 };

void invoke()
{

}
};

Why the enum doesn't compile, while invokeDispatch seems to be fine?

Thanks

--
Fabio.
 
Reply With Quote
 
 
 
 
fabioppp
Guest
Posts: n/a
 
      04-15-2005
fabioppp wrote:
>
> struct Derived1 : public Base<Type1>
> {
> enum { id = 1 };
>
> void invoke()
> {
>
> }
> };



Sorry... it's:

struct Derived1 : public Base<Derived1>
{
enum { id = 1 };

void invoke()
{

}
};

--
Fabio.
 
Reply With Quote
 
 
 
 
James Aguilar
Guest
Posts: n/a
 
      04-15-2005

"fabioppp" <fabioppp_it@yahoo[nospam].it> wrote in message
news:EYQ7e.1240617$(E-Mail Removed)...
> struct Derived1 : public Base<Derived1>
> {
> enum { id = 1 };
> void invoke()
> {}
> };


I'm a relative newbie compared to some of these guys, but it seems to me
like you can't use a class in its own definition. How can the compiler know
what Derived1 does until you finish defining it?

- JFA1


 
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
CRTP Noah Roberts C++ 6 01-15-2007 09:39 AM
CRTP and Factories alexander.stippler@uni-ulm.de C++ 2 07-25-2006 02:35 PM
CRTP question michael.alexeev@qwest.com C++ 2 04-17-2006 06:37 PM
HSSI & cRTP Arthur Lashin Cisco 0 03-19-2005 08:19 AM
ABC vs. CRTP? Mike Smith C++ 7 03-03-2005 05:43 PM



Advertisments