listhelper-moderate
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

help-gplusplus post from address@hidden requires approval


From: help-gplusplus-owner
Subject: help-gplusplus post from address@hidden requires approval
Date: Sun, 08 Jul 2007 20:40:28 -0400

As list administrator, your authorization is requested for the
following mailing list posting:

    List:    address@hidden
    From:    address@hidden
    Subject: can const-arrays be used as class-members?
    Reason:  Post by non-member to a members-only list

At your convenience, visit:

    http://lists.gnu.org/mailman/admindb/help-gplusplus
        
to approve or deny the request.
--- 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 ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]