Reputation: 445
In C++, before define a new variable, how we can find out is there a variable with this name or not?
Upvotes: 1
Views: 231
Reputation: 39380
In general, C++ doesn't have reflection mechanisms, so you can't really check if a variable is defined using C++ code.
You have to use 3rd party tools for that.
Upvotes: 0
Reputation: 461
You should search all parent classes and that class with grep in text mode. And if you use a development studio program like Microsoft visual studio, you can type variable name and wait for auto-cast, it will show if the variable exists.
Upvotes: 2
Reputation: 70929
You can turn on compiler option for warning if a variable is shadowing another one. For instance for GCC this option is -Wshadow
.
Upvotes: 8