I want to use a class which is present in other module and would be available in linking. Size of header file is huge so I don’t want to include header in current module.
I am trying to forward declare class by
class foo;
int foo::getValue();
here getValue() is member function of foo that I want to use.
Now when I am compiling my code I got compilation error before linking as
error: forward declaration of 'struct foo'
What am I missing here?
Thanks,
You can’t forward declare class members, you’ll need to include the whole header.
The correct approach here is to reduce the size of the header. If it only contains the class definition, leave it as it is. If not, there’s potential to break it into multiple headers.
If the class definition is huge, that’a a sign your design is faulty and could be broken up.