Listing 1: A perverse program that uses placement new to alter a
logically-const string object. This is not recommended
// Tested using:
// Borland C++ 5.0
// Microsoft Visual C++ 4.2
#include <iostream>
#include <new>
#include <string>
#ifdef __BORLANDC__
using namespace std;
#endif
void const *
operator new(size_t, void const *p) throw()
{
return p;
}
int main()
{
string const name = "Ben";
cout << name << '\n';
name.string::~string();
new (&name) string ("Jeremy");
cout << name << '\n';
return 0;
}
/* End of File */