473,383 Members | 1,859 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,383 software developers and data experts.

CRTP question

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
2 1790
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
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...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
2
by: alexander.stippler | last post by:
Hi I try to combine two things, which perhaps aren't compatible at all. But I at least look for alternatives: I want to instantiate objects where the type is chosen based on some input...
2
by: Arash Partow | last post by:
Hi all, I've got a question related to emulating aspects of polymorphism with CRTP. Below is a typical polymorphic class hierarchy with a definition of a "somewhat" heterogeneous container of...
3
by: Frank Bergemann | last post by:
Hi, the (gcc-3.4.4) compiler complains, if i try to use a typedef of subclass in superclass: |padsol15 141make Helper_test Helper_test.cc In file included from Helper_test.cc:17:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.