Shoutbox

C++ Bidimensional Array Help! :P - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: C++ Bidimensional Array Help! :P (/showthread.php?tid=47866)

C++ Bidimensional Array Help! :P by leito on 07-21-2005 at 04:26 AM

Hey guys! I'm learning C++ and everything is... was ok. hahaha. I wanted to do a class SquareMatrix and in the constructor get a N integer to create my matrix NxN.

In java that would be:

class SquareMatrix{

     private int matrix[][];
 
     SquareMatrix(int n){
          matrix = new int[n][n];
     }
}

But in C++ I can't do this, and can't find a way to do it. Help neede plz! Thank you in advance!


RE: C++ Bidimensional Array Help! :P by RaceProUK on 07-21-2005 at 04:49 PM

code:
class SquareMatrix{
public:
    SquareMatrix(int n);

private:
    int matrix[][];
}

SquareMatrix::SquareMatrix(int n) {
    matrix = new int[n][n];
}
Get a book ;)

Edit: [code] should also turn on [noparse] :mipdodgy:[/code]
RE: C++ Bidimensional Array Help! :P by leito on 07-22-2005 at 01:28 AM

Thanks raceprouk but it didn't work. I get this error with your code.

"In file Matrix.h declaration of matrix as a multidimensional array must have bounds for all dimensions except the first."

I thought about it, it was like the translation between Java and C++ but it looks like it doesn't work like that in C++, I have some books and a lot of articles on C++, but can't find something like this.


RE: C++ Bidimensional Array Help! :P by RaceProUK on 07-22-2005 at 08:37 AM

Can you tell me which line the error is on?