[gnu.g++.help] problem with operator new and g++1.37.1

ev@chorus.fr (Eric Valette) (10/24/90)

/*
 *
 *	The following program compiles when using Cfront 2.0.
 *	
 *	The syntax used in function f() to call the foo::new operator seems
 *	to be incorrect for g++1.37.1. (this syntax is described in 
 *	" the annotated C++ reference manual" by A. Ellis & B Stroustrup
 *	p 60.
 *	
 *	What is the correct syntax for g++1.37.1?
 *	
 *	NB : I can not use a global __user_new operator (I have exactly the
 *	same problem in many classes).
 *	
 *	I need an answer in order to compile the chorus kernel with g++ !!
 *	
 *	Thanks,
 *	
 */


extern "C" {

char * malloc(int size);
void free(void*);

}

// typedef unsigned long size_t; // for g++
typedef unsigned int size_t; 

class foo {
	char * ptrData;
	int x;
public:
	foo (int j);
	int get () {return x;}
	void* operator new (size_t , int stringSize);
	void* operator new (size_t) {return 0;}	// just to make Cfront 2.0 happy
						// (needed for global object)
	void  operator delete (void*);
};

	void*
foo::operator new (size_t fooSize, int stringSize) {
	
	return malloc(fooSize + stringSize);
}

	void
foo::operator delete (void* ptr) {
	
	free(ptr);
}

foo::foo (int j) {
	x =j;
	ptrData = ((char *) this + sizeof(foo));
}

int f()
{

	// with g++ I get a parse error on the following line :
	foo *ptr = new (100) foo(2);
	return ptr->get();
	
}

/*
 *
 *
   __                 
  /  `                   	Eric Valette
 /--   __  o _.          	Chorus Systemes
(___, / (_(_(__         	6 avenue Gustave Eiffel
				F-78182, St-Quentin-en-Yvelines-Cedex

Tel: +33 (1) 30 64 82 00	Fax: +33 (1) 30 57 00 66
E-mail: ev@chorus.fr		or ev%chorus.fr@mcsun.EU.net

 *
 *
 */