I have a class that spans over two files. It is declared in a declare.h file and defined in define.cpp file.
define.h
class A{
public: int a;
void func(){ a = some_other_func(); }
A();
};
define.cpp
A::A(){
a =0;
}
The overall idea is to initialize a variable in constructor before using it in an inline function. But the constructor definition and function definition are in different files. Is there any issue with this?
There is absolutely no issue with the declaration/definition separation, provided
declare.his included indefine.cpp. But the usulal practice is for implementation files to have the same name as declaration files, bar the suffix. So your case could beA.handA.cpp.However, there is an issue with the initialization of member variable
aitself. You may want to initializeint ain the constructor initialization list:In your code, it is not being initialized at all . You are creating and initializing a local variable called
aa local variable in the body of the constructor. Presumably that is not what you intended.