What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » C++ Bidimensional Array Help! :P

C++ Bidimensional Array Help! :P
Author: Message:
leito
Senior Member
****

Avatar
Chameleon by KeyStorm

Posts: 720
Reputation: 5
38 / Male / –
Joined: Apr 2003
O.P. Undecided  C++ Bidimensional Array Help! :P
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!
[Image: leonelgalan.png]
07-21-2005 04:26 AM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: C++ Bidimensional Array Help! :P
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:

This post was edited on 07-21-2005 at 04:50 PM by RaceProUK.
[Image: spartaafk.png]
07-21-2005 04:49 PM
Profile PM Web Find Quote Report
leito
Senior Member
****

Avatar
Chameleon by KeyStorm

Posts: 720
Reputation: 5
38 / Male / –
Joined: Apr 2003
O.P. RE: C++ Bidimensional Array Help! :P
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.
[Image: leonelgalan.png]
07-22-2005 01:28 AM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: C++ Bidimensional Array Help! :P
Can you tell me which line the error is on?
[Image: spartaafk.png]
07-22-2005 08:37 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On