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

Re: [blug-prog] C++ destructor related problem.

Expand Messages
  • Philip Tellis
    ... Note: go nowhere. Unless nRows==1, this loop will never execute. ie, you re not deleting anything. If nRows==1, the loop will execute infinitely. You
    Message 1 of 3 , Oct 24, 2006
    • 0 Attachment
      Sometime on Oct 24, Pardeep Kumar, Goyal (Goyal)** CTR ** assembled some...:

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

      Note: go nowhere. Unless nRows==1, this loop will never execute. ie,
      you're not deleting anything. If nRows==1, the loop will execute
      infinitely. You probably wanted to say i>=0;

      > 2) Also If I want to initialize the array objects with other than default
      > constructor, how to do so ?

      You can't. At least not the way you want to do it.

      You can do something like this though:

      foo f[3] = {foo(1), foo(), foo(3)};

      to create an array of 3 foos each with a different value.
    • Om Narasimhan
      ... Wrong logic it seems. you have i=0 (I think you meant 0 == i) Assume nRows = 10 before the loop, then, for ( i = 9, 0 == i, i --) {...} Won t execute,
      Message 2 of 3 , Oct 24, 2006
      • 0 Attachment
        > //Deleting ofNoUse Objects.
        >
        > for ( int i=nRows-1; i=0; i-- ) // NOTE: Go Reverse.
        > delete []myofNoUse[i];
        > delete []myofNoUse;
        > (cout<<"\nIS myofNoUse deleted? ").flush();
        > }
        > I have two problems in this program. I ran this program in Linux Fedora.
        > Here I am initializing a 2-dimensional array using new. I can see
        > constructor calls and it is happening fine.
        >
        > 1) But while deallocating the array the default destructor is not getting
        > called. Please let me know why ?
        Wrong logic it seems.
        you have i=0 (I think you meant 0 == i)
        Assume nRows = 10 before the loop, then,
        for ( i = 9, 0 == i, i --) {...}
        Won't execute, since i != 0.
        Fix the logic first.

        Regards,
        Om.
      Your message has been successfully submitted and would be delivered to recipients shortly.