Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force compiler to reveal type of a variable

I am compiling a rather large project in which I faced with

error: ‘CRoom room’ redeclared as different kind of symbol

Right at

class CRoom
{
.....
} room("test");

The problem is that I searched into the whole my project files and I could not find such a variable anywhere else. Is it possible to force the complier to tell me where it has found the original place of such definition? If it is not possible, at least, is it possible to reveal the type of the original variable at comfile time (Note that this programs has so many other errors and I cannot run it and show variable type. I want the compiler reveals the type for me).

like image 981
barej Avatar asked Feb 03 '15 13:02

barej


1 Answers

For getting the compiler to show me the type of something, I usually use an improptu class like this:

template <class T>
struct show_type;

Then, in the code where you need to learn a type, you'd do this:

show_type<decltype(room)> t;

Compile this, and the compiler will rightfully complain that show_type<T> is not defined; but the error message will helpfully spell out the T with which the instantiation was attempted.

like image 108
Angew is no longer proud of SO Avatar answered Sep 18 '22 06:09

Angew is no longer proud of SO