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

[LONG]Simple RTTI

P: n/a
If I implement a simple RTTI system, more simple than C++ RTTI system
for my program and this system is plus or minus:

#define DEF_RTTI_BASE(name) virtual inline const char *Name(){ return
#name; }
#define DEF_RTTI(name) inline const char *Name(){ return #name; }

And(for example)

class CProva
{
public:
CProva(){};
~CProva(){};
DEF_RTTI_BASE(CProva)
};

class CProvaDerived
{
public:
CProvaDerived(){};
~CProvaDerived(){};
DEF_RTTI(CProvaDerived)
};

int main()
{
CProva p;
CProvaDerived d;
std::cout << "Base: " << p.Name()<< "\n";
std::cout << "Derived: " << d.Name()<< "\n";
char cexit = std::cin.get();
return 0;
}

This system is a valid RTTI subsystem that can subsitute the C++ RTTI
and I can use it in my program without the dipendens of the C++ RTTI system?

--
Tnk

Luca "Kleidemos" Francesca

Un computer a un altro quando si incontrano:
"Ciao, come ti boota oggi???"
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Kleidemos wrote in news:nJ*********************@news3.tin.it in
comp.lang.c++:
If I implement a simple RTTI system, more simple than C++ RTTI system
for my program and this system is plus or minus:


Before you "re-implement" RTTI what's your problem with the language
features (that are always present BTW) commonly refered to as RTTI ?

IOW: whats your question ? or what (if any) is your problem ?

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

P: n/a
Rob Williscroft wrote:

Before you "re-implement" RTTI what's your problem with the language
features (that are always present BTW) commonly refered to as RTTI ?

It's, IMHO, more Os dipendent and more complicate and wrong
implementated than how it could be.
--
Tnk

Luca "Kleidemos" Francesca

Un computer a un altro quando si incontrano:
"Ciao, come ti boota oggi???"
Jul 22 '05 #3

P: n/a

"Kleidemos" <fr***********@tin.it> wrote in message
news:nJ*********************@news3.tin.it...
If I implement a simple RTTI system, more simple than C++ RTTI system
for my program and this system is plus or minus:

#define DEF_RTTI_BASE(name) virtual inline const char *Name(){ return
#name; }
#define DEF_RTTI(name) inline const char *Name(){ return #name; }

And(for example)

class CProva
{
public:
CProva(){};
~CProva(){};
DEF_RTTI_BASE(CProva)
};

class CProvaDerived
{
public:
CProvaDerived(){};
~CProvaDerived(){};
DEF_RTTI(CProvaDerived)
};

int main()
{
CProva p;
CProvaDerived d;
std::cout << "Base: " << p.Name()<< "\n";
std::cout << "Derived: " << d.Name()<< "\n";
char cexit = std::cin.get();
return 0;
}

This system is a valid RTTI subsystem that can subsitute the C++ RTTI
and I can use it in my program without the dipendens of the C++ RTTI system?


Why do you have two macros? Using DEF_RTTI_BASE works exactly the same.

class CProvaDerived
{
public:
CProvaDerived(){};
~CProvaDerived(){};
DEF_RTTI_BASE(CProvaDerived)
};

john
Jul 22 '05 #4

P: n/a
John Harrison wrote:

Why do you have two macros? Using DEF_RTTI_BASE works exactly the same.

class CProvaDerived
{
public:
CProvaDerived(){};
~CProvaDerived(){};
DEF_RTTI_BASE(CProvaDerived)
};

john


Tanks for yout advise ;)
--
Tnk

Luca "Kleidemos" Francesca

Un computer a un altro quando si incontrano:
"Ciao, come ti boota oggi???"
Jul 22 '05 #5

P: n/a
Kleidemos wrote in news:TD*********************@news3.tin.it in
comp.lang.c++:
Rob Williscroft wrote:

Before you "re-implement" RTTI what's your problem with the language
features (that are always present BTW) commonly refered to as RTTI ?


It's, IMHO, more Os dipendent and more complicate and wrong
implementated than how it could be.


Ok, what dosen't it do that you want ?.

AFAICT you code solved the problem that:

typeid( <object-reference> ).name()

return's an implementation defined "string", but it imposes that *every*
object be polymorphic. In effect its a variation of "everything is an
`Object` (i.e. is-a/derived from)" systems (as in jave/c# etc) that
have been tried and abandoned countless times:

Perhapse you will find:

http://lists.boost.org/MailArchives/boost/msg64112.php

(subject "[boost] typeof")

interesting.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #6

P: n/a

"Rob Williscroft" <rt*@freenet.co.uk> wrote in message
news:Xn**********************************@130.133. 1.4...
Kleidemos wrote in news:TD*********************@news3.tin.it in
comp.lang.c++:
Rob Williscroft wrote:

Before you "re-implement" RTTI what's your problem with the language
features (that are always present BTW) commonly refered to as RTTI ?
It's, IMHO, more Os dipendent and more complicate and wrong
implementated than how it could be.


Ok, what dosen't it do that you want ?.

AFAICT you code solved the problem that:

typeid( <object-reference> ).name()

return's an implementation defined "string", but it imposes that *every*
object be polymorphic. In effect its a variation of "everything is an
`Object` (i.e. is-a/derived from)" systems (as in jave/c# etc) that
have been tried and abandoned countless times:


Microsoft's MFC uncannilly similar implementation demonstrates your point
very well.
Perhapse you will find:

http://lists.boost.org/MailArchives/boost/msg64112.php

(subject "[boost] typeof")

interesting.


What purpose does the OP anticipate using this 'facility' to accomplish?
IIRC, the only uses for RTTI are serialization and multiple dispatch. In
which case boost::serialization should be of interest as well at
www.rrsd.com. Certainly C++ RTTI is sufficient for MultipleDispatch examples
that I've seen to date.

Jeff F
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.