overload delete[] operator with specific arguments

We're trying to overload the delete[] operator with specific arguments. Which is the right way to call it? We use the GNU compiler and obtain compiler errors with all of these samples:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
using namespace std;

typedef unsigned int P;

struct A{
	static allocator<A>m;
	P p;
	void*operator new[](size_t s){return m.allocate(s);}
	void operator delete[](void*p,int s){m.deallocate((A*)p,s);}
};

int main(){
	A*a=new A[10];
	//delete (5) []a;
	//delete[5]a;
	//delete[] (5) a;
	//delete[]a (5);
	//delete[]((int)5)a;
	//delete[]a((int)5);
	return 0;
}
operator delete does not take an int as an argument.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
using namespace std;

typedef unsigned int P;

struct A{
    static allocator<A>m;
    P p;
    void*operator new[](size_t s){return m.allocate(s); }
    void operator delete[](void*p, size_t s){m.deallocate((A*) p, s); }
};

int main(){
    A*a = new A[10];
    delete[] a;
}


You might benefit from reading:
http://stackoverflow.com/questions/7194127/how-should-i-write-iso-c-standard-conformant-custom-new-and-delete-operators/7195226#7195226

Thank you very much cire for your time and your answer :D
Last edited on
Topic archived. No new replies allowed.