Topic: ARM pg 151: definition of aggrigate


Author: grumpy@cbnewse.cb.att.com (Paul J Lucas)
Date: Fri, 15 Oct 1993 22:24:48 GMT
Raw View


Author: daniels@biles.com (Brad Daniels)
Date: Fri, 15 Oct 1993 15:21:31 GMT
Raw View
In article <1993Oct14.182910.6005@integrity.uucp>,
Duane Voth <duanev@mpd.tandem.com> wrote:
>On page 151 the ARM states:
>
>    "An aggregate is an array or an object of a class with no
>    constructors, no private or protected members, ..."
>
>which means that the following class CANNOT be used with a static
>initializer:
>
>    class string {
>    public:
>        string()                                { ptr = 0; }
>        string(char * s)                        { ptr = s; }
>        string(const string & s)                { ptr = s.ptr; }
>        string operator=(const string & s)      { return ptr = s.ptr; }
>        operator char *()                       { return ptr; }
>
>    private:
>        char * ptr;
>    };
>
>
>thanks to the three constructors and the private "ptr".
(etc.)

No...  It means you cannot initialize an object of the class using *aggregate*
initialization.  Ctor initialization is legal.

E.g., you can say:

 string s="Hello"; // use char * ctor

but not:

 string s={"Hello"}; // aggregate initialization - error

The following is also legal:

>    typedef struct map {
>        int x;
>        string y;
>    };
>
>    map map1[] = { {0, "zero"}, {1, "one"}, {2, "two"}, {0, "three"} };

Here, you'r using aggregate initialization on map1, but each string element
is initialized with the char * ctor.

- Brad
--
----------------------------------------------------------------------
+ Brad Daniels   | "Let others praise ancient times;  +
+ Biles and Associates  |  I am glad I was born in these."   +
+ These are my views, not B&A's |   - Ovid(43 B.C - 17 A.D)    +




Author: duanev@mpd.tandem.com (Duane Voth)
Date: 14 Oct 93 18:29:10 GMT
Raw View
On page 151 the ARM states:

    "An aggregate is an array or an object of a class with no
    constructors, no private or protected members, ..."

which means that the following class CANNOT be used with a static
initializer:

    class string {
    public:
        string()                                { ptr = 0; }
        string(char * s)                        { ptr = s; }
        string(const string & s)                { ptr = s.ptr; }
        string operator=(const string & s)      { return ptr = s.ptr; }
        operator char *()                       { return ptr; }

    private:
        char * ptr;
    };


thanks to the three constructors and the private "ptr".
So, much as one would like to be able to say:

    typedef struct map {
        int x;
        string y;
    };

    map map1[] = { {0, "zero"}, {1, "one"}, {2, "two"}, {0, "three"} };

and in other contexts:

    string name = "duane";

the current ARM deffinition refuses to allow this requiring two
separate "string" classes one with constructors and one without.

I believe the reason for this limitation is that a class with
constructors with executable code cannot be statically initialized
properly in a link-time != run-time environment.  Fine, but my
constructors do nothing more than static initializations (WHEN
supplied with static constants).  I claim that what I ask is nothing
more than what current C/C++ compilers do already with static
initializations - it's just that the *implementation* becomes
trickier.

Even if "no private or protected members" are required, I would like
to see the ability to use static initializers with less restrictive
class definitions.
--
--- duane voth   kc5bgv                         duanev@mpd.tandem.com
--- ALL systems are arbitrary!  Effectiveness is the measure of Truth
--