This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc: C++ 2D array initialisation problem
- To: gcc-help at gcc dot gnu dot org
- Subject: Re: gcc: C++ 2D array initialisation problem
- From: Brendan J Simon <brendan dot simon at bigpond dot com>
- Date: Tue, 16 Jan 2001 10:27:29 +1100
- References: <3A6381A9.9040701@ctam.com.au>
- Reply-To: brendan dot simon at bigpond dot com
Brendan J Simon wrote:
> I have a problem initialising a 2D array of a class.
> The problem only seems to show up if it is a const declaration.
> The sample code below gives the following error with g++ (ver 2.95.2)
>
> array.cpp: In function `void
> __static_initialization_and_destruction_0(int, int)':
> array.cpp:28: conversion from `const FOO[3]' to non-scalar type `FOO'
> requested
> array.cpp:28: conversion from `const FOO[3]' to non-scalar type `FOO'
> requested
> array.cpp:28: conversion from `const FOO[3]' to non-scalar type `FOO'
> requested
>
> Is this a g++ error or an error in the code ???
>
> Please reply to me (brendan.simon@bigpond.com) as well as the list.
> Thanks for any advice, tips or pointers.
> Brendan Simon.
>
> -----------------------------------------------------------------------------
>
> #include <iostream>
>
> enum VALUE { min, med, max };
>
> class FOO
> {
> public:
> FOO( VALUE value ) : _value(value) { }
> char _value;
> };
>
> FOO foo1[3] = { min, med, max };
>
> FOO foo2[3][3] = {
> { min, med, max },
> { min, max, med },
> { max, med, min }
> };
>
> const FOO foo3[3] = { min, med, max };
>
> const FOO foo4[3][3] = {
> { min, med, max },
> { min, max, med },
> { max, med, min }
> };
>
> int main()
> {
> return 0;
> }
>