Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement member functions in cpp2 file #1357

Unanswered
abuehl asked this question in Q&A
Discussion options

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.

You must be logged in to vote

Replies: 1 comment 9 replies

Comment options

See #594.

You must be logged in to vote
9 replies
Comment options

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?

Comment options

Sorry, I don't understand.
IIRC, including the .h2 includes the interface and not the implementation.

Comment options

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.

Comment options

You can include the logging library in widget.cpp2, between the declarations (.h2) and definitions (.hpp).

Comment options

I see. Not ideal for the user, but at least it is achievable indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /