#include #include class Counter { public: void decrement() { --ref_; } Counter() : ref_(1) {} int ref() const { return ref_; } private: int ref_; }; template< typename T > class Foo { public: void resetData() { ref_.decrement(); std::cout << "before: " << ref_.ref() << std::endl; ref_.~Counter(); void *refLoc = &ref_; // GCC erroneously claims that the following line has no // effect. But it does have an effect: the value of the // "after" message will be 0 instead of 1 if you comment it // out. new ( refLoc ) Counter(); std::cout << "after: " << ref_.ref() << std::endl; } private: Counter ref_; }; int main() { Foo< int > node; node.resetData(); }