J
Joseph Paterson
Hi all,
This has popped up in a project that I'm working on, and I was
wondering whether it is ok/not ok, and what really happens in the
following case.
I have a base class for most of my classes, called IObject. It
basically has grab()/drop() methods, which increment/decrement a
reference counter. drop() calls delete this if the reference counter
reaches 0. They also have a string object, which holds a debug name:
class IObject
{
public:
IObject() : reference_counter(1) {}
void grab();
void drop();
string getDebugName();
};
then I have two classes, say IA (interface to A), and A. I was doing
the following, and got no mistakes:
class IA : public IObject
{
};
class A : public IA, public IObject
{
};
When I create an object of type A, what goes on exactly? Does it
inherit from two IObject instances, and does it have two reference
counters?I put a printf statement in the constructor of IObject, and
it seems that it actually just gets called once, but is that right?
Thanks in advance for any guidance on this,
Joseph Paterson.
This has popped up in a project that I'm working on, and I was
wondering whether it is ok/not ok, and what really happens in the
following case.
I have a base class for most of my classes, called IObject. It
basically has grab()/drop() methods, which increment/decrement a
reference counter. drop() calls delete this if the reference counter
reaches 0. They also have a string object, which holds a debug name:
class IObject
{
public:
IObject() : reference_counter(1) {}
void grab();
void drop();
string getDebugName();
};
then I have two classes, say IA (interface to A), and A. I was doing
the following, and got no mistakes:
class IA : public IObject
{
};
class A : public IA, public IObject
{
};
When I create an object of type A, what goes on exactly? Does it
inherit from two IObject instances, and does it have two reference
counters?I put a printf statement in the constructor of IObject, and
it seems that it actually just gets called once, but is that right?
Thanks in advance for any guidance on this,
Joseph Paterson.