Anthony Raimondo
Anthony Raimondo

Reputation: 1721

Getting reference to a typeid() object?

Hey im coming from a java background, im reading a c++ book and it says that typeid() returns an object of type_info. But if i try to do something like;

type_info *x = typeid(somthing);

I get the error : no suitable conversion from const type_info to type_info exists.

Can someone tell me how i can get a reference to a type_info object?

Upvotes: 1

Views: 116

Answers (1)

mfontanini
mfontanini

Reputation: 21900

The typeid operator returns a const type_info&. Therefore, you need a const reference, not a pointer:

const std::type_info &x = typeid(something);

Upvotes: 4

Related Questions