typeid problems -- _non_r

E

ezelasky

I am programming in microsoft VC++ 7.1 and get an unhandled exception
when I use typeid on a deferenced pointer.

So I tried the example below, from the msdn site and I am seeing the
same error as with my code, "Unhandled exception ...
__non_rtti_object__".

Perhaps I am missing a setting or something in my environment?

Thanks, Elizabeth

class Base {
public:
virtual void vvfunc() {}
};

class Derived1 : public Base {};

Derived1* pd = new Derived1;
Base* pb = pd;
cout << typeid( *pb ).name() << endl;
delete pd;


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
B

Bruno van Dooren

you have to compile with run-time type information enabled:
right-click your project, select configuration properties ->
c/c++ ->language and set 'enable run time type info' to yes.

that will solve it.

for more info look for 'typeid operator' in MSDN.

kind regards,
Bruno.
 
M

Mikhail Kubzin

Did you enable RTTI in Project - Properties - C/C++ - Language - Enable
Runtime Type Info (/GR option of the compiler)?

Regards,
Mikhail

I am programming in microsoft VC++ 7.1 and get an unhandled exception
when I use typeid on a deferenced pointer.

So I tried the example below, from the msdn site and I am seeing the
same error as with my code, "Unhandled exception ...
__non_rtti_object__".

Perhaps I am missing a setting or something in my environment?

Thanks, Elizabeth

class Base {
public:
virtual void vvfunc() {}
};

class Derived1 : public Base {};

Derived1* pd = new Derived1;
Base* pb = pd;
cout << typeid( *pb ).name() << endl;
delete pd;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
M

Michiel.Salters

I am programming in microsoft VC++ 7.1 and get an unhandled exception
when I use typeid on a deferenced pointer. ....
__non_rtti_object__".

Perhaps I am missing a setting or something in my environment?

Just a guess: you have turned off RTTI ? Standard C++ requires RTTI
features,
but the Microsoft compiler allows you to turn them off. A useless
option IMO
(if you want to cut the overhead, remove it during linking) which just
makes
testing double the work for them.

Of course, in that case easch object is a non-RTTI object, but I'd
expect the
compiler to reject typeid as well.

HTH,
Michiel Salters
class Base {
public:
virtual void vvfunc() {}
};

class Derived1 : public Base {};

Derived1* pd = new Derived1;
Base* pb = pd;
cout << typeid( *pb ).name() << endl;
delete pd;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
J

Jim Langston

I am programming in microsoft VC++ 7.1 and get an unhandled exception
when I use typeid on a deferenced pointer.

So I tried the example below, from the msdn site and I am seeing the
same error as with my code, "Unhandled exception ...
__non_rtti_object__".

Perhaps I am missing a setting or something in my environment?

Thanks, Elizabeth

class Base {
public:
virtual void vvfunc() {}
};

class Derived1 : public Base {};

Derived1* pd = new Derived1;
Base* pb = pd;
cout << typeid( *pb ).name() << endl;
delete pd;

The following program compiles and runs and produces the output
class Derived1
in Microsoft Visual C++ .net 2003

#include <iostream>
#include <string>

class Base
{
public:
virtual void vvfunc() {}
};

class Derived1 : public Base {};

int main()
{
Derived1* pd = new Derived1;
Base* pb = pd;
std::cout << typeid( *pb ).name() << std::endl;
delete pd;
std::string Wait;
std::cin >> Wait;
}


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

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

Top