Loading ...
Sorry, an error occurred while loading the content.

Small C++ problem

Expand Messages
  • Pardeep Kumar, Goyal (Goyal)** CTR **
    Hi All, If you are not C++ programmer please ignore my mail. I am extremely sorry for posting my problem in this forum. My problem is in C++ program. But
    Message 1 of 1 , Oct 24, 2006
    • 0 Attachment
      Hi All,



      If you are not C++ programmer please ignore my mail.

      I am extremely sorry for posting my problem in this forum. My problem is in
      C++ program. But didn't get any reply from other C++ groups I have joined.

      Trying my luck here. This simple program is eating my brains out.





      class ofNoUse

      {

      private: int val;

      public:



      ofNoUse()

      {

      cout<< "\nCreatingofNoUseObjectByDefault";

      cout.flush();

      }



      ofNoUse(int i)

      {

      val=i;

      cout<<"\nCreatingofNoUseObjectNotByDefault";

      cout.flush();

      }



      ~ofNoUse()

      {

      cout<<"\nDestroyingofNoUse";

      cout.flush();

      }

      };







      int main()

      {



      int **mArr1;

      int nRows,nCols;



      cout<<"Rows:";

      cin>>nRows;

      cout<<"Cols:";

      cin>>nCols;

      cout.flush();



      ofNoUse **myofNoUse;

      myofNoUse = new ofNoUse*[nRows];

      for(int i=0;i<nRows;i++)

      myofNoUse[i]=new ofNoUse[nCols];



      (cout<<"\nofNoUse Object Created").flush();







      //Deleting ofNoUse Objects.



      for ( int i=nRows-1; i=0; i-- ) // NOTE: Go Reverse.

      delete []myofNoUse[i];

      delete []myofNoUse;

      (cout<<"\nIS myofNoUse deleted? ").flush();

      }









      That's it. Everything works fine while new'ing up the multidimensional array
      dynamically. I can see constructor calls being printed.

      But while deallocating destructor doesn't seems to be called at all. I
      don't know where I am missing something.



      I am not sure what blunder I am doing here.



      Thanks

      Pardeep





      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.