I learn C++ at the moment and as far as I know instance variables should be declared in a Header file. An example header (.hpp) looks like:
class myClass {
private:
int i;
std::ifstream file;
anotherClass aClassObj;
public:
//methods
}
I would like to initialize the variables in my source file (.cpp). For int it's only:
i = 4;
How would I do it for instance variables? In Java it would be variableName = new Classname(ConstructorParam1, ConstructorParam2);
However this is not possible in C++ because file = new ifstream("filename");
results in a type mismatch as new <...>;
returns a pointer.
Should I do a file.open("filename");
instead or something else?
How can I initialize my variable aClassObj
, I would like to call a constructor with parameters?
Kind regards