This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16441] Problen in overloading delete operator.


------- Additional Comments From uttamkumar at hotmail dot com  2004-07-09 12:38 -------
(In reply to comment #0)
> I have compilation problem in overloading operator delete.

/********************************************
 File : test.cpp 
 How to compile:
 g++ -g -D_REENTRANT -Wall -ansi -ggdb3 -c  test.cpp
 ********************************************/
#include<stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std ;

inline void     operator delete (void *reportedAddress , const char *file,int 
line,const char *func)
{
        cout<< "Delete:"<<" File:"<<file<< " Line:"<<line<<" Func:"<<endl;
        free ( reportedAddress ) ;
        return ;
}
void*   operator new (size_t size, const char *file,int line,const char *func)
{
        cout<< "New:"<<size<<" File:"<<file<< " Line:"<<line<<" 
Func:"<<func<<endl;
        return malloc ( size ) ;
}
#ifdef new
#undef new
#endif

#ifdef delete
#undef delete
#endif

#define new new ( __FILE__, __LINE__, __FUNCTION__)
#define delete  delete ( __FILE__, __LINE__, __FUNCTION__)


typedef struct {
                  int x;
                  int y ;
                  char s[100] ;
}MyStruct ;


void DummyFunction () {
        MyStruct *m = new MyStruct () ;
        delete m ;
        return ;
}

int main (){
        DummyFunction () ;
        return 0 ;
}




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16441


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]