[LONG]Simple RTTI

K

Kleidemos

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???"
 
R

Rob Williscroft

Kleidemos wrote in 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.
 
K

Kleidemos

Rob said:
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???"
 
K

Kleidemos

John said:
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???"
 
J

John Harrison

Kleidemos said:
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
 
R

Rob Williscroft

Kleidemos wrote in in
comp.lang.c++:
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.
 
J

Jeff Flinn

Rob Williscroft said:
Kleidemos wrote in in
comp.lang.c++:


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top