-
Notifications
You must be signed in to change notification settings - Fork 258
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
[Question] Is there a way to call delegating constructor? #409
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
Comments
It seems there's no way. IIRC, you should also be able to delegate to any
|
Well calling directly seems to work
However technically thats not delegated constructor, but calling assign operator (which I think provided according to that diagram from wiki |
Interesting. I tried with explicit |
Btw is there syntax for initialization like cpp1 |
No. Just use assignments. See https://github.com/hsutter/cppfront/wiki/Cpp2:-operator=,-this-&-that#misc-notes. |
Probably there is no need for delegating constructors at all and this can be solved in the future with just one constructor, default values, and named parameters in. |
I think it's an accident that #409 (comment) works. |
Well I think it works but not exactly how it is expected.
Which boils down to Edit: in other words, it's not forbidden to initialize same member different times with different values. May be thats issue, may be not. |
Looking closely, that (double assignment) seems to be the case |
Another exaggerated example for your #409 (comment)
cppfront doesn't track data flow that |
In wiki it's stated that cpp2 guarantees initialization, that means initializing at least once, but it's not clear if that means exactly once and not more. |
It's OK to. |
I think assignment to Also, something should be decided about
But currently, it lowers to Cpp1 as |
Thanks for exploring the issue. My understanding is that delegating constructors are not supported right now, but can be introduced in the future. Is that correct? Should I edit this issue to match suggestion template? Few thoughts that came to me while reading the thread: Cpp2 encourage use of overloading while default values for arguments are not supported. Default arguments would fit nicely in the scenario with Calling directly does work, but also reverse logic where most general constructors chain calls to more specialized. It feel more like workaround due to initialization code being more convoluted in the end. Double assignment here is ok'is. Feel like compromise. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I'm plaing with cppfront trying to port some bits of code to get a feel of new syntax.
One thing I cannot figure out is how to write
operator=:
to delegate construction.I tried
operator=: (out this, major: u32) = this(major, 0, 0, 0);
,operator=: (out this, major: u32) = this := (major, 0, 0, 0);
, even stared withoperator=: (out this, major: u32) = Version(major, 0, 0, 0);
.In cppfront source I didn't found code emitting, but I'm not yet 100% sure.
Did I missed the intended syntax or feature is not present at this time? Thanks!
For reference:
The text was updated successfully, but these errors were encountered: