gcc: C++ 2D array initialisation problem
Brendan J Simon
brendan.simon@bigpond.com
Mon Jan 15 14:27:00 GMT 2001
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;
> }
>
More information about the Gcc-help
mailing list