Replies: 14 comments 5 replies
|
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. |
Uh oh!
There was an error while loading. Please reload this page.
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:
All reactions