Chavoosh
Chavoosh

Reputation: 445

How we can know is there a specific variable in C++ or not?

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

Answers (3)

Bartek Banachewicz
Bartek Banachewicz

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

ibrahim demir
ibrahim demir

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

Ivaylo Strandjev
Ivaylo Strandjev

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

Related Questions