Two things are going on:
1) you re-declare testValue1 here by putting int in front:
generalVars()
{
cout << "I am in general vars constructor" << endl;
int testValue1= 555; //right here!
cout << "testValue1 has been set " << testValue1 << endl;
}
This hides the class's own instance of testValue1 with a new unique variable by the same name. You can reference both like so:
generalVars()
{
cout << "I am in general vars constructor" << endl;
int testValue1= 555; //note, still has int
cout << "testValue1 has been set " << testValue1 << endl;
cout << "this->testValue1 has not been set and is " << this->testValue1 << endl;
this->testValue1 = 555; //note, this->
cout << "this->testValue1 has been set " << this->testValue1<< endl;
}
Or you could avoid the name clash and refer to it normally:
generalVars()
{
cout << "I am in general vars constructor" << endl;
testValue1= 555; //note, no int. This is identical to this->testValue1
cout << "testValue1 has been set " << testValue1 << endl;
}
Next is not really an issue, but should be noted:
You do not need to heap allocate things with new in C++ most of the time. You should prefer stack allocated objects
generalVars myObject;
instead of:
generalVars *myObject = new generalVars();
...
delete myObject;
Or, in cases where you do want to create a heap allocated object:
auto myObject = std::make_unique<generalVars>();
Or, if you need multiple handles:
auto myObject = std::make_shared<generalVars>();
The unique_ptr and shared_ptr examples do not require explicit deletion. The heap allocation will be deleted when the pointer object goes out of scope. This especially helps with exception safety.