If VS.Net actually optimizes the const member function pointers, then I'm impressed, and it really will be cheap.

However, someone said that anonymous union names is not standard C++ -- that's false; the standard specifies that you don't have to name a union, and the naming of the inner elements then bind to the outer scope. So that's a pretty good solution.

Another solution is to realize that the struct layout rules still hold for classes as long as the classes don't have virtual member functions. Thus, this good-old solution is eqiuvalently cheap, and will not be expensive on less studly compilers (like GCC):

Original post by hplus0603However, someone said that anonymous union names is not standard C++ -- that's false; the standard specifies that you don't have to name a union, and the naming of the inner elements then bind to the outer scope. So that's a pretty good solution.

You don't have to name the union, but you sure do have to name its members. This :

i tell what would be even more impressive if someone could figure out a way to either use this technique or combined approach with unions maybe so you could return a reference to either column vector or row vector from a matrix (not nessecarilly by overloading sub-script operator) without making copies of either one and it might lead to a quick tranpose operation?

Edit: Ok you can overload operatators on POD types anyway I'm sure, but really this solves a problem that doesn't exist with a solution that's incomprehensible. Try slipping that past your boss and see if it comes back to bite you.

2. Fine fair enough so just say for a minute you started with the union method later on you decide that you wont to make some constructors in you main vector type using constructor initializer lists using the non-array members i.e. vec x, y, z, w, the only way you can do this is by giving the internal structure vec a constructor aswell but this also isn't standard compliant code because union members are not suppose to have constructors & destructors.

pointer to data members are not hacks, its completely legitimate standard compilant code & is probably safer than using public unions.

Quote:

Original post by bobstevens
that's incomprehensible.

you can easily make the "incomprehensible" part private not the case with unions so much [smile]