Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUGGESTION] Question: Why 'a function must have a body'? #608

Closed
jazn opened this issue Aug 21, 2023 · 2 comments
Closed

[SUGGESTION] Question: Why 'a function must have a body'? #608

jazn opened this issue Aug 21, 2023 · 2 comments

Comments

@jazn
Copy link

jazn commented Aug 21, 2023

I found that cppfront requires class function to be defined in declaration. (https://github.com/hsutter/cppfront/blob/main/source/sema.h#L1076)
In c++ definition and declaration are more independent.

I wonder why this constrain exists?

UPDATE:
I have a basic (simple?) problem: how can I include a cpp2 header with class definition in two .cpp2 files and link them together. I will get 'multiple definition' error on linking.

@JohelEGP
Copy link
Contributor

I found that cppfront requires class function to be defined in declaration. (https://github.com/hsutter/cppfront/blob/main/source/sema.h#L1076) In c++ definition and declaration are more independent.

I wonder why this constrain exists?

Cpp2 function bodies are order independent.
So their relative order in a source file doesn't matter.
The README mentions:

An alternative syntax would let us do things we can never do within today's syntax without breaking the world:

  • [...]
  • make it easy to write refactoring and other tools (e.g., have order-independent semantics).

UPDATE: I have a basic (simple?) problem: how can I include a cpp2 header with class definition in two .cpp2 files and link them together. I will get 'multiple definition' error on linking.

This problem was brought to light by the discussion at #594.

@jazn
Copy link
Author

jazn commented Aug 23, 2023

Thanks for pointing that out.

@jazn jazn closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants