Replies: 14 comments 5 replies
-
It seems there's no way. IIRC, you should also be able to delegate to any
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Interesting. I tried with explicit |
Beta Was this translation helpful? Give feedback.
-
Btw is there syntax for initialization like cpp1 |
Beta Was this translation helpful? Give feedback.
-
No. Just use assignments. See https://github.com/hsutter/cppfront/wiki/Cpp2:-operator=,-this-&-that#misc-notes. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
I think it's an accident that #409 (comment) works. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Looking closely, that (double assignment) seems to be the case |
Beta Was this translation helpful? Give feedback.
-
Another exaggerated example for your #409 (comment)
cppfront doesn't track data flow that |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
It's OK to. |
Beta Was this translation helpful? Give feedback.
-
I think assignment to Also, something should be decided about
But currently, it lowers to Cpp1 as |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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:
Beta Was this translation helpful? Give feedback.
All reactions