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

typeid problems -- _non_r

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! ]

Jan 12 '06 #1
4 1351
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.

<ez******@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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! ]

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

Regards,
Mikhail

ez******@hotmail.com wrote:
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! ]

Jan 13 '06 #3
ezela...@hotmail.com wrote:
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! ]

Jan 13 '06 #4
<ez******@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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! ]

Jan 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Andreas Sch. | last post by:
Hello, I had been quite suprised by the following little program: ---- cut ---- #include "iostream.h" class base {
11
by: Jamie Burns | last post by:
Hello, I just did a simple benchmark: for (xx=0;xx<100000;xx++) { rDerived* derived = dynamic_cast<rDerived*>(object); if (derived) derived->setValue(message.data.messageSetInt.value); } ...
3
by: Mike | last post by:
I want to use typeid() in a base class function to determine the name of the derived class. typeid(this) returns the name of the base class (which is an abstract class) rather than the derived...
19
by: Marco Jez | last post by:
Hi everyone! I would like to use the reference returned by typeid as key in a std::map. Is it safe to assume that typeid(T) (where T is a type name) will always return the same reference to the...
18
by: Adam Zimny | last post by:
This is fragment of code from Bruce Eckel's Thinking in c++ ( last 3 couts are mine to show what happened ). The question is: is Bruce Eckel wrong or g++ ( my version is 3.2.3 ) is buggy ? //:...
5
by: nobody | last post by:
With Visual C++ 2005 beta 2, I get the below compling error for the following code. I think this error is not acceptable to me because int::typeid is a constant and is known to compiler when...
6
by: ma740988 | last post by:
I was trying to garner a feel for typeid and it's use with polymorphic types #include <iostream> template <class T> bool is_polymorphic() { bool result(false); typeid( (result=true),...
1
by: Ralf Propach | last post by:
Hi, in C# I can write Type listType = typeof(System.Collections.Generic.List<>); What is the equivalent in C++? I get compiler errors for all of the following: Type listType =...
7
by: Deepak Jharodia | last post by:
I'm using a templatized class in GCC based environ template<class A, class B> class foo {... ....} F; Now I want to know that particular instance of this class was instantiated with what...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.