struct piece {
    piece(){}
    piece(int spacs[][3])
    {
        spaces = spacs;
    }
    int spaces[][3];
};

/home/myname/Programming/C++/blokus1/game.hpp|11|error: incompatible types in assignment of ‘int (*)[3]’ to ‘int [0][3]'

How can this be fixed?

Recommended Answers

All 6 Replies

Welcome to C (not C++) where arrays and pointers are almost synonymous. Consider an STL vector<tuple<int,int,int> > instead?

You could define it like int* spaces[3];

NathanOliver is almost right, but I at least do like to distinguish "define" and "declare". A declaration is about type whereas a definition is about value. So I would say you could declare it as int* spaces[3] . Since this is C++, you do have access to all the STL classes which in my opinion make both programming and learning to program easier, so I continue to recommend that frenchie4111 consider using a std::vector unless his teacher says not.

I do agreee that vectors do have advantages but this is still c++. It is still usefull to know how to do these things because there are times when you would be better of with a 2d array instead of a 2d vector.

Of course some C++ programmers will need to understand how to deal with pointers to multi dimensional arrays, but I suspect many student programmers never will need such skills, so I'm really talking more about the order that concepts are introduced to new C++ programmers. I started from C, so I had my trial by fire before I ever heard of C++. Perhaps because of that, I may appreciate more than most how much easier it is now than it was before there was an STL in the standard.

My own take, which is certainly not universal, is that student programmers will make much better progress if we introduce string, vector, iteration, etc earlier rather than later; and allow them to concentrate at first on what it means to do programming, rather than how to overcome what will seem to them like obscure and esoteric errors.

I got it to work using std::vector< boost::tuple<int,int,int> > thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.