Search code examples
c++classinstance-variables

What is the exact definition of instance variable?


I think instance variables are simple data types like int or double. Everything that is created automatically when the object is created.

If an object creates additional objects - like everything that is it done with the NEW keyword - these are not instance variables.

Am I right or wrong? What is the exact definition?


Solution

  • Wrong. Anything that is bound within the instance (i.e. an instantiated object) is instance variable. As opposite of static (class) variables, which are bound to the class. It doesn't matter if they are simple types or pointers to objects.