By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

CRTP question

P: n/a
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.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Jul 23 '05 #2

P: n/a

"fabioppp" <fabioppp_it@yahoo[nospam].it> wrote in message
news:EY***********************@news4.tin.it...
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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.