Topic: constructing unnamed classes / explicit as default
Author: c141592653589@hotmail.com (MJ)
Date: Fri, 16 May 2003 18:47:30 +0000 (UTC) Raw View
A class without a name cannot be initialized, because it isn't
possible to define a constructor. Example:
class {
... // how define a constructor?
} x(17);
If it were allowed to use keyword 'this' for constructors, then it
would be possible to initialize an unnamed class.
If so, then it would be a good opportunity to change the default for
those constructors to 'explicit'. An 'implicit' constructor could be
declared by making use of recycled keyword 'auto'. Examples:
class {
..
public:
this(int a) {} // explicit
this(int a, int b) {} // explicit
} x(2), y(7, 13);
class MyString {
..
public:
auto this(const char* s) {} // implicit
};
So far I can't think of any collision with the other meanings of
'this' and 'auto'. Can anyone?
Would it be a language change of interest?
Michael
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]