Re: Returning more than one variable? - Help

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 09/23/04


Date: Thu, 23 Sep 2004 19:19:53 +0100

In article <230920041733534001%dt015a1979@mac.com.invalid>, Alwyn
<dt015a1979@mac.com.invalid> wrote:
>
> Um, isn't it also part of the definition of POD that all data members
> must be 'public'? Surely, that class above would need a constructor to
> initialise it?

Sorry to reply to my own posting, but i'm a little confused about what
POD really is.

Marshal Cline's FAQ says:
<http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7>
<quote>
A type that consists of nothing but Plain Old Data.

 A POD type is a C++ type that has an equivalent in C, and that uses
the same rules as C uses for initialization, copying, layout, and
addressing.

 As an example, the C declaration struct Fred x; does not initialize
the members of the Fred variable x. To make this same behavior happen
in C++, Fred would need to not have any constructors. Similarly to make
the C++ version of copying the same as the C version, the C++ Fred must
not have overloaded the assignment operator. To make sure the other
rules match, the C++ version must not have virtual functions, base
classes, non-static members that are private or protected, or a
destructor. It can, however, have static data members, static member
functions, and non-static non-virtual member functions.

 The actual definition of a POD type is recursive and gets a little
gnarly. Here's a slightly simplified definition of POD: a POD type's
non-static data members must be public and can be of any of these
types: bool, any numeric type including the various char variants, any
enumeration type, any data-pointer type (that is, any type convertible
to void*), any pointer-to-function type, or any POD type, including
arrays of any of these. Note: data-pointers and pointers-to-function
are okay, but pointers-to-member are not. Also note that references are
not allowed. In addition, a POD type can't have constructors, virtual
functions, base classes, or an overloaded assignment operator.
</quote>

However, here I found:
<http://www.devphil.com/~pme/reflection.html>
<quote>
Some brief definitions from the C++ standard:
POD
Plain Old Data
POD-struct
"an aggregate class that has no non-static data members of type
pointer to member, non-POD-struct, non-POD-union (or array of such
types) or reference, and has no user-defined copy assign-ment operator
and no user-defined destructor."
POD-union
"an aggregate union that has no non-static data members of type
pointer to member, non-POD-struct, non-POD-union (or array of such
types) or reference, and has no user-defined copy assignment operator
and no user-defined destructor."
POD-class
A class that is either a POD-struct or a POD-union.
</quote>

This looks official, so can I take it as authoritative? It would seem
that Cline's explanation cum simplified definition goes a lot further
than this. What think you?

Alwyn



Relevant Pages

  • Re: Trouble with offsetof
    ... >It's not clear to me though what makes foo not a POD. ... In your stripped example, it is just the private members, but I ... - no non-static members of type pointer to member ...
    (comp.lang.cpp)
  • Re: Returning more than one variable? - Help
    ... >POD really is. ... It can, however, have static data members, static member ... >functions, base classes, or an overloaded assignment operator. ... Comeau C/C++ with Dinkumware's Libraries... ...
    (alt.comp.lang.learn.c-cpp)
  • Re: is this class POD ?
    ... >> a POD, regardless of how you set up accessibility. ... Since compilers are allowed to reorder data members that have different ... protected shares the same physical attributes as one that has only public data ...
    (comp.lang.cpp)
  • Re: Two questions for help!
    ... > Ioannis Vranos wrote: ... > So if the internal representation (data members) some day change, ... not change the interface pointer value. ...
    (comp.lang.cpp)
  • Re: Class and static member
    ... > data members are used by this static method. ... nonstatic methods can access static variables since you need to ... Marius ...
    (microsoft.public.vc.language)