DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   error help (http://www.daniweb.com/forums/thread39295.html)

tyczj Feb 7th, 2006 2:07 pm
error help
 
cant figure out this error. im trying to do a 3 dimensional static array that just displays the number in a matrix form

ex: 1111111
1111111
1111111

im sure the error has somethin to do with the depth, row and col being constants but i dont knwo how to fix it cause that how its suppose to be

Quote:

: error C2440: 'initializing' : cannot convert from 'const int' to 'struct Node [6][8][4]'
There are no conversions to array types, although there are conversions to references or pointers to arrays

Space::Space()
{
int number = 0;
error Node array[DEPTH][ROW][COL] = NULL;

};


#include <iostream>
#include <string>

using namespace std;


struct Node
{
        int number;
        bool open;
        char color;
};


class Space {

        private:
        #define DEPTH 6
        #define ROW 8
        #define COL 4

        Node array[DEPTH][ROW][COL];

        public:

        Space();
        ~Space();
        Space(const Space& space);
        Space& operator= (Space&(const Space& space));
        void setAllNodes();
        void print();
       

};


void main()
{

       

};

void Space::setAllNodes()
{
        for(int d=0; d<DEPTH; d++)
                for(int j=0; j<ROW; j++)
                        for(int k=0; k<COL; k++)
                        {
                          array[d][j][k].open = true;
                          array[d][j][k].color = 'j';
                          array[d][j][k].number = d;
                        }
};

void Space::print()
{
        int k = 0;
        for(int i=0; i<DEPTH; i++) {
                for(int j=0; j<ROW; j++) {
                        for(int k=0; k<COL; k++)
                        {
                                cout << array[i][j][k].number << ' ';
                        }
                                cout << endl;
                }

        }
        cout << endl;

}


Space::Space()
{
        int number = 0;
  error     Node array[DEPTH][ROW][COL] = NULL;

};

Space::~Space() { }

Space::Space(const Space& space)
{
       
       
};

Space&  Space::operator= (Space&(const Space& space))
{
       

        return *this;
};

WolfPack Feb 7th, 2006 2:54 pm
Re: error help
 
Try only this
Node array[DEPTH][ROW][COL];

tyczj Feb 7th, 2006 3:16 pm
Re: error help
 
it gives me a warning but it runs now atleast thx

dwks Feb 9th, 2006 5:04 pm
Re: error help
 
Try this:
Node array[DEPTH][ROW][COL] = {{{NULL}}};
That should get rid of your error and your warning.


All times are GMT -4. The time now is 8:37 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC