M
Marcel Müller
I have a base class that provides a swap() method.
In a derived class I have some caching. Swapping the Base slice makes
sense, but it invalidates the cache. No problem if *this is the derived
class, I could simply override swap. But what if the derived class is
the argument to swap?
class Base
{
virtual void swap(Base& right);
};
class Derived
{
int SomeCache;
virtual void swap(Base& right);
}
Base b();
Derived d();
b.swap(d);
Then Base::swap is called, which obviously knows nothing about Derived.
Is there a way to come around that?
Marcel
In a derived class I have some caching. Swapping the Base slice makes
sense, but it invalidates the cache. No problem if *this is the derived
class, I could simply override swap. But what if the derived class is
the argument to swap?
class Base
{
virtual void swap(Base& right);
};
class Derived
{
int SomeCache;
virtual void swap(Base& right);
}
Base b();
Derived d();
b.swap(d);
Then Base::swap is called, which obviously knows nothing about Derived.
Is there a way to come around that?
Marcel