"Cheng Mo" <mo******@nospam.nospam> wrote...
When overriding operator new & delte of one class, the method is
implicitly declared as static. However, overriding operator new & delete
of template cannot be static.The compiler says cannot declare the function
a static linkage. Why?
C++ is so complex and so many situation should be considered.
Read the FAQ 5.8.
This:
--------------------
#include <typeinfo>
#include <iostream>
template<class T>
class A {
public:
A(int) {}
void * operator new(size_t s) {
std::cout << "new A<" << typeid(T).name() << ">\n";
return malloc(s); }
void operator delete(void* p, size_t s) { free(p); }
};
int main()
{
A<int> *paint = new A<int>(42);
}
--------------------
compiles just fine (as it should)
V