Click here to Skip to main content
15,916,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Strange operator new in MSDN sample code Pin
Maxwell Chen6-Jan-08 21:41
Maxwell Chen6-Jan-08 21:41 
GeneralRe: Strange operator new in MSDN sample code Pin
CPallini6-Jan-08 21:50
mveCPallini6-Jan-08 21:50 
GeneralRe: Strange operator new in MSDN sample code Pin
Matthew Faithfull6-Jan-08 23:45
Matthew Faithfull6-Jan-08 23:45 
GeneralRe: Strange operator new in MSDN sample code Pin
Maxwell Chen7-Jan-08 0:39
Maxwell Chen7-Jan-08 0:39 
GeneralRe: Strange operator new in MSDN sample code Pin
Matthew Faithfull7-Jan-08 0:55
Matthew Faithfull7-Jan-08 0:55 
GeneralRe: Strange operator new in MSDN sample code Pin
Maxwell Chen7-Jan-08 1:12
Maxwell Chen7-Jan-08 1:12 
GeneralRe: Strange operator new in MSDN sample code Pin
Matthew Faithfull7-Jan-08 1:36
Matthew Faithfull7-Jan-08 1:36 
GeneralRe: Strange operator new in MSDN sample code Pin
Member 7549607-Jan-08 5:00
Member 7549607-Jan-08 5:00 
No doubt the article is poorly written. If you follow the links and read the grammer for the placement operator new you should come up with the following for the sample class (see following note below):

class A {
public:
    A(int) { throw "Fail!"; }

	void *operator new(size_t stAllocateBlock);
	void *operator new(size_t stAllocateBlock, char chInit);
	void *operator new(size_t stAllocateBlock, char*, int);
};

// a simple new
void *A::operator new(size_t stAllocateBlock)
{
	void *pvTemp = ::malloc( stAllocateBlock );
	return pvTemp;
}

// a placement new with 3 arguments
void * A::operator new(size_t stAllocateBlock, char*, int)
{
	void *pvTemp = ::malloc( stAllocateBlock );
	return pvTemp;
}

// a placement new with 2 arguments
void * A::operator new(size_t stAllocateBlock, char chInit)
{
	void *pvTemp = ::malloc( stAllocateBlock );
	if( pvTemp != 0 )
		memset( pvTemp, chInit, stAllocateBlock );
	return pvTemp;
}

If you compile this you will get the warning (C4291) that the article is trying to highlight. If you provide a placement new operator for a class you need to provide a matching delete operator.
GeneralRe: Strange operator new in MSDN sample code Pin
Maxwell Chen7-Jan-08 6:19
Maxwell Chen7-Jan-08 6:19 
GeneralCStatusBar Pin
vethathiri6-Jan-08 18:41
vethathiri6-Jan-08 18:41 
GeneralRe: CStatusBar Pin
Rajesh R Subramanian6-Jan-08 20:30
professionalRajesh R Subramanian6-Jan-08 20:30 
Questionabout : Resource-only Dll Pin
Punit Shah6-Jan-08 18:23
Punit Shah6-Jan-08 18:23 
QuestionRe: about : Resource-only Dll Pin
Rajesh R Subramanian6-Jan-08 19:17
professionalRajesh R Subramanian6-Jan-08 19:17 
GeneralRe: about : Resource-only Dll Pin
Maxwell Chen6-Jan-08 19:24
Maxwell Chen6-Jan-08 19:24 
JokeRe: about : Resource-only Dll Pin
CPallini6-Jan-08 21:34
mveCPallini6-Jan-08 21:34 
JokeRe: about : Resource-only Dll Pin
Maxwell Chen6-Jan-08 21:45
Maxwell Chen6-Jan-08 21:45 
GeneralMFC Radio button question Pin
CodingLover6-Jan-08 18:23
CodingLover6-Jan-08 18:23 
GeneralRe: MFC Radio button question Pin
Haroon Sarwar6-Jan-08 19:02
Haroon Sarwar6-Jan-08 19:02 
QuestionRe: MFC Radio button question Pin
David Crow7-Jan-08 3:33
David Crow7-Jan-08 3:33 
Generalcompilation error Pin
gentleguy6-Jan-08 17:09
gentleguy6-Jan-08 17:09 
GeneralRe: compilation error Pin
Maxwell Chen6-Jan-08 17:15
Maxwell Chen6-Jan-08 17:15 
GeneralRe: compilation error Pin
gentleguy6-Jan-08 20:25
gentleguy6-Jan-08 20:25 
GeneralRe: compilation error Pin
Maxwell Chen6-Jan-08 20:30
Maxwell Chen6-Jan-08 20:30 
GeneralRe: compilation error Pin
Michael Dunn6-Jan-08 20:22
sitebuilderMichael Dunn6-Jan-08 20:22 
GeneralRe: compilation error Pin
gentleguy6-Jan-08 20:36
gentleguy6-Jan-08 20:36 

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.