I have a class Property with a constructor in which I want default parameters, in a file property.h:
class Property {
Property(OtherClass* value = myApp->someValue) {...};
};
where myApp, of another type Application, is defined in another file that makes extensive use of this Property class. Since this other file #includes property.h, of course, I cannot #include this file in property.h
property.h does not know about myApp nor Application (though property.cpp does, and OtherClass is known in property.h).
I could forward declare OtherClass and declare myApp as extern, but this results in an error C2027 "use of undefined type Application", as expected :
class Application;
extern Application* myApp;
class Property {
Property(OtherClass* value = myApp->someValue) {...};
};
A solution could be to have the default parameter in the .cpp file, but this is not advisable (here).
How can I get this default parameter working ? (i.e., not another solution that would involve not having default parameters telling me default parameters are evil, or that my design is poor to start with etc. ;) ). Thanks!
.ccwhereApplicationis known. (Try to make an MCVE to check it out...)