--- Begin Message ---
Subject: |
can const-arrays be used as class-members? |
Date: |
09 Jul 2007 00:11:14 GMT |
class C {
const int ar[3];
public:
C(int k) : ar({k,2*k,3*k}) {}
C(const C& c) : ar(c.ar) {}
};
does not compile! none of those constructors did manage to initialize C::ar,
and leaving C::ar uninitialized is an error too. did I overlook something?
is there any C++ implementation of the good old const-sized C-arrays? I guess
something like this could be the solution:
template<typename T_, unsigned char size=256> struct array {
T_ carray[size]; //public for compatibility with C-functions
template<typename T__> array(const array<T__, size>& a);
array(T_, ...);//initialize by iterating over all arguments
T_& operator[](const unsigned char i) {return carray[i];}
operator array<T_, size-1> (); //reinterpret_cast to smaller array...
template<unsigned char s_>
array<T_, size-s_> operator+ (s_); //the same but using the tail...
};
template<typename T_, unsigned short int size> struct array :
array< array<T_>, 1+ size/256> {/*add implementation here*/};// :-)
and of course above "int ar[3]" would then need to be replaced by
"array<int,3> ar" and initialization would work without any {} around
the list of terms. but don't try this at home :-)...
does anyone know of similar implementations? how would g++ handle such
an array-class during optimization, would it be the same as T_[size]?
--
Better send the eMails to netscape.net, as to
evade useless burthening of my provider's /dev/null...
P
--- End Message ---
--- Begin Message ---
Subject: |
confirm 9e3a2a97d519c7620879759971f4de761f21354f |
If you reply to this message, keeping the Subject: header intact,
Mailman will discard the held message. Do this if the message is
spam. If you reply to this message and include an Approved: header
with the list password in it, the message will be approved for posting
to the list. The Approved: header can also appear in the first line
of the body of the reply.
--- End Message ---