Sign in to follow this  

custom RTTI - using the preprocessor

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have my own run time type info. system which goes something like this:
class BaseClass
{
enum
	{
		Type = -1,
		ParentType = -1,
	};

	virtual unsigned int GetType() { return Type; }
	virtual unsigned int GetParentType() { return ParentType; }
};

class ClassA : public BaseClass
{
enum
	{
		Type = 1,
		ParentType = BaseClass::Type,
	};


	virtual unsigned int GetType() { return Type; }
	virtual unsigned int GetParentType() { return ParentType; }
};

class ClassB : public ClassA
{
enum
	{
		Type = 2,
		ParentType = ClassA::Type,
	};


	virtual unsigned int GetType() { return Type; }
	virtual unsigned int GetParentType() { return ParentType; }
};

now, i want to change this to use macros, and i want the preprocessor to generate the Type = xxx I saw a thread on here once about a preprocessor macro that would increment a value each time it was used, but i forgot what it was.

Share this post


Link to post
Share on other sites
__COUNTER__ is almost certainly reset for each compilation unit though, so you'll probably need to define all of your IDs in one unit (Or header and make sure that __COUNTER__ isn't used elsewhere).

Share this post


Link to post
Share on other sites
i assume __COUNTER__ is microsoft specific, better than nothing for now though :) . Would also be nice if there was a general cross platform solution.

Can you explain further how this typelists' can be used for RTTI?

Share this post


Link to post
Share on other sites

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this