-
Notifications
You must be signed in to change notification settings - Fork 269
-
If I define a class (aka type) in CPP2 syntax (in a .h2 file), is it possible to just declare the member functions in the class definition (without body) and have the actual implementation separated in the .cpp2 file? If yes, how is it done? I'm thinking about things like the traditional PIMPL pattern for reducing compilation dependencies.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 9 replies
-
See #594.
Beta Was this translation helpful? Give feedback.
All reactions
-
That's a good find Johel.
Is it currently smart enough to add to the .h exclusively the includes needed for the interface, and leave all other includes for the .hpp?
Beta Was this translation helpful? Give feedback.
All reactions
-
Sorry, I don't understand.
IIRC, including the .h2 includes the interface and not the implementation.
Beta Was this translation helpful? Give feedback.
All reactions
-
Not the .h2, the .h. As in your example where main.cpp2 does #include "widget.h".
To make the question concrete: If Widget.sum did some logging, would widget.h include the headers for the logging library (unnecessary)? Or only the widget.hpp file would?
The relevance being that if the answer is no, then this won't help for the "traditional PIMPL pattern for reducing compilation dependencies" in the OP.
Beta Was this translation helpful? Give feedback.
All reactions
-
You can include the logging library in widget.cpp2, between the declarations (.h2) and definitions (.hpp).
Beta Was this translation helpful? Give feedback.
All reactions
-
I see. Not ideal for the user, but at least it is achievable indeed.
Beta Was this translation helpful? Give feedback.