Topic: Initialisation of an array class attribute in a constructor


Author: "Sony E Antony" <jamsav@capital.net>
Date: 1997/01/19
Raw View
Hi,
 Array member cannot be initialised in the real sense. For a detailed
discussion, see ARM ( Annoted C++ Reference manual ) by Ellis & Stroustrup
sec 12.6.1 page 290.
class Test
{
    public:
        Test();
    private:
        int Integer;
        char Array[2];
};

Test::Test(char elmnt1,elmnt2) :
        Integer(0),

{
Array[0] = elmnt1;
Array[1] = elmnt1;
}

As you can see this is a case of assignment. In purticular there is no way
to have const array member as they cannot be initialised.
Regards
Sony E Antony.



Geert Bevin <gbevin@arcadis.be> wrote in article
<5bs7qd$955@netlab.cs.rpi.edu>...
> Hello,
>
> I have a problem with the initialisation of array attributes in a
constructor
> declaration. I know how to initialise regular attributes, but I can't
find a
> way to do it with arrays.
>
> [I think this may be covered in the FAQ, but I don't remember for sure...
--mod]
>
> // Example:
> // --------
>
> class Test
> {
>     public:
>         Test();
>     private:
>         int Integer;
>         char Array[10];
> };
>
> Test::Test() :
>         Integer(0),
>         Array(?????)    // <- how do I initialise the array?
> {
> }
[quote trimmed, dup mod sig snipped --mod]

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]