Why is the Watch-Window showing empty "DBName" for my Second class? Do i have to assign my first class to the second to inherit the values?
Constructor?
And before you ask: No, the Variable holding the first class has not gone out of scope (neither the second variable).
EDIT: To clarify: I want to inherit the values of an already created (and filled) instance of a class
I see, so actually the debugger shows correct.
Yes you have to "assign" (copy each of) the values to your new class.
-------------
You need to differentiate between:
- the class (defines the structure, but does not hold data itself)
- the instance (holds the data)
Each instance has its own data. An instance does not "inherit" from another instance.
An inherited class only shares the structure.
-----------
Also note:
This does NOT copy the instance.
It gives you 2 variables, both referring to the same instance. (there is a hidden pointer, and you only copy the pointer)
So you need to copy each field on its own.
----------
However, if you want changes in your CMySQLDB instance, to also ALWAYS immediately be reflected in your instance of CMySQLDBConfig, then you may want to use "delegation"
That means the 2nd instance has a variable holding a reference to the 1st instance (copy of pointer).
And in the 2nd instance you fetch the data from the first instance when needed.