Ok changed the above to:
nd.h
Code:
namespace T {
class Dummy {
int *p;
double q;
public:
Dummy();
~Dummy();
void DoSomething();
};
};
nd.cpp
Code:
#include <iostream>
#include "nd.h"
namespace T{
void* operator new(std::size_t t)
{
std::cerr<<"Hello I'm new"<<std::endl;
return malloc(t);
}
void operator delete(void *ptr)
{
std::cerr<<"Laters"<<std::endl;
free(ptr);
}
Dummy::Dummy()
{
p = new int;
}
Dummy::~Dummy()
{
T::operator delete( p );
}
void Dummy::DoSomething()
{
*p = 5;
std::cout<<"p = "<<*p<<std::endl;
}
};
ndmain.cpp
Code:
#include <iostream>
#include "nd.h"
using std::cout;
using std::endl;
int main()
{
cout<<"A dummy is: "<<sizeof(T::Dummy)<<" bytes large\nAn int is "<< sizeof(int) <<" bytes large"<<endl;
T::Dummy *d= new T::Dummy;
d->DoSomething();
delete d;
cout<<"Meh?"<<endl;
}
Output:
A dummy is: 12 bytes large
An int is 4 bytes large
Hello I'm new
p = 5
Laters
Meh?