Click here to Skip to main content
15,921,884 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralA Timeline Editor Pin
James Corrie31-Aug-00 14:06
sussJames Corrie31-Aug-00 14:06 
GeneralDebugging Automation Servers Pin
Steve McCray31-Aug-00 12:15
Steve McCray31-Aug-00 12:15 
GeneralRe: Debugging Automation Servers Pin
Tim Deveaux1-Sep-00 9:31
Tim Deveaux1-Sep-00 9:31 
QuestionHow to change button size on Title bar? Pin
leo31-Aug-00 12:06
leo31-Aug-00 12:06 
AnswerRe: How to change button size on Title bar? Pin
Erik Funkenbusch31-Aug-00 12:12
Erik Funkenbusch31-Aug-00 12:12 
Generaltext files Pin
antonio salomone31-Aug-00 10:37
antonio salomone31-Aug-00 10:37 
GeneralRe: text files Pin
Alex Gorev31-Aug-00 10:45
Alex Gorev31-Aug-00 10:45 
GeneralRe: text files Pin
Paolo Messina1-Sep-00 4:39
professionalPaolo Messina1-Sep-00 4:39 
GeneralDrawing on a dialog Pin
Roger31-Aug-00 9:45
Roger31-Aug-00 9:45 
GeneralRe: Drawing on a dialog Pin
Alex Gorev31-Aug-00 10:37
Alex Gorev31-Aug-00 10:37 
GeneralRe: Drawing on a dialog Pin
Roger1-Sep-00 1:51
Roger1-Sep-00 1:51 
GeneralRe: Drawing on a dialog Pin
lauren5-Sep-00 4:43
lauren5-Sep-00 4:43 
Questionhow can I draw large Images in WIN 95? Pin
Dima31-Aug-00 5:05
Dima31-Aug-00 5:05 
AnswerRe: how can I draw large Images in WIN 95? Pin
Steven Mitcham31-Aug-00 5:55
Steven Mitcham31-Aug-00 5:55 
AnswerRe: how can I draw large Images in WIN 95? Pin
Erik Funkenbusch31-Aug-00 12:16
Erik Funkenbusch31-Aug-00 12:16 
AnswerRe: how can I draw large Images in WIN 95? Pin
www.fengyuan.com31-Aug-00 14:27
susswww.fengyuan.com31-Aug-00 14:27 
GeneralWindow from resource Pin
Erik31-Aug-00 4:50
Erik31-Aug-00 4:50 
GeneralRe: Window from resource Pin
Erik Funkenbusch31-Aug-00 12:17
Erik Funkenbusch31-Aug-00 12:17 
GeneralTab key is not working in OCX control -- URGENT Pin
Abdul Kareem31-Aug-00 4:49
Abdul Kareem31-Aug-00 4:49 
GeneralRe: Tab key is not working in OCX control -- URGENT Pin
Igor Chouvalov31-Aug-00 6:07
Igor Chouvalov31-Aug-00 6:07 
GeneralRe: Tab key is not working in OCX control -- URGENT Pin
Abdul Kareem31-Aug-00 7:27
Abdul Kareem31-Aug-00 7:27 
GeneralICommandWithParameters implementation code Pin
hongdongsuk31-Aug-00 0:58
hongdongsuk31-Aug-00 0:58 
Generaloverriding new/delete Pin
Walter Gildersleeve30-Aug-00 21:24
Walter Gildersleeve30-Aug-00 21:24 
GeneralRe: overriding new/delete Pin
Tim Deveaux31-Aug-00 14:00
Tim Deveaux31-Aug-00 14:00 
GeneralRe: overriding new/delete Pin
Tim Deveaux3-Sep-00 3:49
Tim Deveaux3-Sep-00 3:49 
Here's a generic test, for discussion purposes...

#include <stdio.h>
#include <malloc.h>
  
struct test{
    int a;
    int b;
    int c;
  
    void * operator new(size_t);
    void operator delete(void*);
  
    void * operator new[] (size_t); 
    void operator delete[] (void*);
};
  
void * test::operator new(size_t sz)
{
    return malloc(sz);
}
   
void __cdecl test::operator delete(void* t)
{
    free(t);
}
   
void * test::operator new[](size_t sz)
{
    return malloc(sz);
}
   

void test::operator delete[](void* t)
{
    free(t);
}
   
   
int main(int argc, char* argv[])
{
    printf("Hello World!\n"); 
  
    // calls t::new & t::delete
    test* t = new test;
    delete t;
   
    // calls t::new[] & t::delete[]
    t = new test[20];
    delete []t;
   
    // calls global new and delete
    int * p = new int;
    delete p;
   
    return 0;
}


This works as 'expected' on both Borland CPP Builder 4 and MS VC6, but leaves me with another question - I didn't expect to be able to provide an operator delete[] at class scope! Interestingly, if I try to scope the new and delete of the test class (e.g. test::new), I get errors - Borland simply gives 'Expression syntax', whereas VC6 says 'operator xxx must be globally qualified'.

What gives?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.