Quote:
Originally posted by shaver
I guess I was thinking of inline constructors, such that they would become simply a bit of syntactic sugar, and wouldn't incur any penalty for programs that didn't use them. I do appreciate your desire to keep the generated code's size down, though!
|
Well, even if the constructor is defined in-line, there is no guarantee that the compiler will actually inline it, so it may still result in dead code. In fact, with older linkers that do not eliminate duplicate inline functions, having the inline constructor can result in getting a separate copy in every object file that includes the header file in which the structure is defined (although, I suspect that pretty much all linkers these days are smart enough to eliminate the duplicates).
Quote:
|
Very true, though using that sort of static initialization as part of an expression (for me, commonly, function arguments) makes for some ugly typing.
|
Yes, that doesn't look too pretty... If you are really keen on having the constructor, you can derive a struct from the one that is generated by the slice2cpp compiler and define the constructor for that:
Code:
struct MyPosition : public Position {
MyPosition(int x, int y, int z) : Position(x, y, z) {}
};
foo(MyPosition(a, b, c));
I think that, overall, this solution is preferable, given that it is trivial to implement.
Cheers,
Michi.