25/12/2007, 23h59
|
#6
|
|
|
Re: Unusual C construct - What is it?
Erik Wikström wrote:
> On 2007-12-25 18:47, mczard@poczta.onet.pl wrote:
>>>> const struct ast_datastore_info dialed_interface_info = {
>>>> .type ="dialed-interface",
>>>> .destroy = dialed_interface_destroy,
>>>> .duplicate = dialed_interface_duplicate,
>>> This is part of C99 syntax and those variables are designated
>>> initialisers. It makes it easier to track which fields are set during
>>> that initialization. It is not valid in C++ though.
>> If you need such a thing in C++, you have to use external
>> configuration files (try http://harpoon.sourceforge.net; my project to
>> be honest). I really wish it were a part of C++, as well as list
>> literals; and not only for initialization. For example:
>
> The fact that C++ have constructors mitigates the problem slightly, and
> if that is not enough you can use comments.
>
> struct Point {
> Point(intx, int y);
> };
>
> Point(/*x = */ 10, /*y = */ 25);
>
>
>> draw_line( Point( x = 10, y = 25 ), Point( x = 50, y = 25 ) );
The named parameter idiom might be useful,
http://www.parashift.com/c++-faq-lit...html#faq-10.18
LR
|
|
|
|