Re: Unusual C construct - What is it?
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 ) );
std::vector<int> list( { 1, 4, 5, 2 } );
Will be in the next version of the standard, but with slightly different
syntax.
--
Erik Wikstr?m