Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > class with two ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 45894 of 48020
Post > Topic >>

class with two dimensional array as a member (I need help)

by Pawel_Iks <pawel.labedzki@[EMAIL PROTECTED] > May 12, 2008 at 11:49 PM

Hello!

I'd like to have a two dimensional array as a member of a class, bu if
I did it in the following way:

class A {
   const int n;
   int a[n][n];
public:
   A(int nn): n(nn) {};
  ~A() {};
};

this produce error, when I changed it to:

class A {
   const int n;
   int** a;
public:
   A(int nn): n(nn) {
      for (int i=0;i<n;i++)
         a[i]=new int[n];
   }
   ~A() {
      for (int i=0;i<n;i++)
         delete [] a[i];
     }
};

it works fine, however when I tried to use it in some program like
this:

int main() {
   int x,y;
   A a(10);
   return 0;
}

program compiled without any problems, but when I run it it was thrown
an unknown exception ... I don't understand what is going on.
 




 4 Posts in Topic:
class with two dimensional array as a member (I need help)
Pawel_Iks <pawel.labed  2008-05-12 23:49:30 
Re: class with two dimensional array as a member (I need help)
"Alf P. Steinbach&qu  2008-05-13 09:18:07 
Re: class with two dimensional array as a member (I need help)
James Kanze <james.kan  2008-05-13 02:50:18 
Re: class with two dimensional array as a member (I need help)
"Alf P. Steinbach&qu  2008-05-13 12:05:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:40:54 CDT 2008.