home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18365 < prev    next >
Encoding:
Text File  |  1992-12-23  |  1.4 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!hcla!jyc
  3. From: jyc@hcla.com (Joy Chhugani)
  4. Subject: new and delete in MFC and BorlandC
  5. Message-ID: <1992Dec23.230359.15065@hcla.uucp>
  6. Sender: jyc@hcla.uucp (Joy Chhugani)
  7. Organization: HCL America, Inc.,
  8. Date: Wed, 23 Dec 1992 23:03:59 GMT
  9. Lines: 53
  10.  
  11.  
  12.  
  13. I am using Microsoft's MFC with Borland's C++ 3.1 IDE.
  14.  
  15. This is a rough sketch of a class that I have -
  16.  
  17. class Foo
  18. {
  19. private:
  20.     CPoint        *pts;
  21.     ...
  22.  
  23. public:
  24.     Foo(const CPoint    init[], short    num);
  25.  
  26.     virtual
  27.     ~Foo(void)
  28.     {
  29.         delete [] pts;            // <-------------   ::operator delete
  30.     }
  31.     ...
  32.     ...
  33. };
  34.  
  35. Foo::Foo(const CPoint    init[], short    num)
  36. {
  37.     if (pts = new CPoint[num])  // <-------------   _vector_new 
  38.     {
  39.         for (short i = 0; i < num ; i++)
  40.             pts[i] = init[i];
  41.     }    
  42. }
  43.  
  44. The problem is that MFC's overloaded global operators new and delete
  45. are incompatible with BorlandC's internal memory allocation functions.
  46.  
  47. In the Foo constructor the pts member points to an array allocated by
  48. "_vector_new" which is presumably an internal BorlandC function.
  49.  
  50. In the destructor surprisingly the MFC overloaded global operator delete
  51. functions gets called. This does some memory usage check which fails.
  52.  
  53. Has anybody encountered this problem or am I doing something that is
  54. wrong ? Any workarounds, solutions, suggestions etc. are welcome.
  55.  
  56. Thanks in advance for the replies.
  57.  
  58.  
  59. --
  60. Joy Chhugani
  61. jyc@hcla.com
  62. uunet!hcla!jyc
  63.  
  64.