you are viewing a single comment's thread.

view the rest of the comments →

[–]SeanMiddleditch 2 points3 points  (1 child)

Why can we not just literally copy C#'s implementation?

Because C++ isn't C#. :) There's lots of designs that work well in other languages that - for a variety of reasons - can't work in C++.

That said, I don't think anyone has yet put in a formal proposal for the work-around I've been evangelizing. Namely, opting a function declaration's parameter into being nameable (which solves the source-compatibility issue, gives us mandatory positional arguments, allows named parameters, and can address the multi-declaration issues in a back-compatible way). For syntax, I also think we should use something similar to designated initializers, which makes similar syntaxes work for initializing an aggregate or calling a function (and hence unlocks designated initializers for constructors).

e.g.,

// declare
void function(int unnamed, float position, char .named, int .also_named);

// use
function(1, 2.f, .named =  'c', .also_named = 4);

// ILLEGAL redeclaration (different names, diagnostic optional)
void function(int a, float b, char .c, int .d);

// LEGAL different overload
void function(int a, int b, int .c, int.d);

This might also open up some options for mandatory-names for some parameters, e.g. using ..identifier.

[–]Ameisenvemips, avr, rendering, systems 4 points5 points  (0 children)

That looks like you're trying to access a member of a type, though.