L
lmfmaw
Hi all,
I've hit the wall with this "fairly" simple problem. As you can see in
the code below, my destructors don't do their job as they are supposed
to (I left them empty for this example). I'm running the Visual Leak
Detector library (on VS 2005) to detect memory leaks and whatever I've
tried it still complains..
Please can someone help me clean up properly?
--------
#include <iostream>
using namespace std;
class Base {
public:
Base(int baseInt) { m_baseInt=baseInt; }
virtual ~Base() {}
virtual void behave() const { cout << "I'm Base." << endl; }
virtual void prnt() const { cout << m_baseInt << endl; }
int m_baseInt;
};
class Derived : public Base {
public:
Derived(int baseInt, int derivedInt): Base(baseInt)
{ m_derivedInt=derivedInt; }
~Derived() {}
void behave() const { cout << "I'm Derived!" << endl; }
void prnt() const { cout << m_baseInt << " : " << m_derivedInt <<
endl; }
private:
int m_derivedInt;
};
int main() {
Base *anBase[2];
anBase[0] = new Base(11);
anBase[1] = new Derived(100, 1907);
for(int i = 0; i < 2; i++) {
anBase->behave();
anBase->prnt();
}
return 0;
}
I've hit the wall with this "fairly" simple problem. As you can see in
the code below, my destructors don't do their job as they are supposed
to (I left them empty for this example). I'm running the Visual Leak
Detector library (on VS 2005) to detect memory leaks and whatever I've
tried it still complains..
Please can someone help me clean up properly?
--------
#include <iostream>
using namespace std;
class Base {
public:
Base(int baseInt) { m_baseInt=baseInt; }
virtual ~Base() {}
virtual void behave() const { cout << "I'm Base." << endl; }
virtual void prnt() const { cout << m_baseInt << endl; }
int m_baseInt;
};
class Derived : public Base {
public:
Derived(int baseInt, int derivedInt): Base(baseInt)
{ m_derivedInt=derivedInt; }
~Derived() {}
void behave() const { cout << "I'm Derived!" << endl; }
void prnt() const { cout << m_baseInt << " : " << m_derivedInt <<
endl; }
private:
int m_derivedInt;
};
int main() {
Base *anBase[2];
anBase[0] = new Base(11);
anBase[1] = new Derived(100, 1907);
for(int i = 0; i < 2; i++) {
anBase->behave();
anBase->prnt();
}
return 0;
}