S
S. I. Becker
Is it possible to determine if a function has been overridden by an
object, when I have a pointer to that object as it's base class (which
is abstract)? The reason I want to do this is that I want to call this
function if it has been overridden, and not if it hasn't, e.g
class CBase
{
public:
virtual long mightBeOverridden(int i) { return 0; } // not a pure
virtual function, since sub-classes should not have to define it
bool isFunctionOverRidden() { return false; }// This is what I want
to code
virtual int id()=0; // this class is an abstract class because of
this function - I don't think that this is relevant but more info is good
};
class CDerived1
{
// Does not override the function
int id() { return 1; }
};
class Derived2
{
long mightBeOverridden(int i) { return i; }
// Should not have to also override isAboveFunctionOverRidden()
int id() { return 2; }
};
class Derived3
{
long mightBeOverridden(int i) { return i * i; }
// Should not have to also override isAboveFunctionOverRidden()
int id() { return 3; }
};
int foo(CBase* pObj, int i, int j)
{
if(pObj)
{
if(pObj->isFunctionOverridden())
return mightBeOverridden(i);
}
return j;
}
I googled on this and came up with nought, as did a search of this list.
I'm guessing that means it's impossible. I thought that I might
compare function pointers ( return mightBeOverridden !=
CBase::mightBeOverridden ) but that doesn't distinguish between the two.
If it's relevant, I'm using MS Visual C++ 7.0 (aka .NET 2002), due to
upgrade to 8.0 soon.
Thanks in advance,
Stewart
object, when I have a pointer to that object as it's base class (which
is abstract)? The reason I want to do this is that I want to call this
function if it has been overridden, and not if it hasn't, e.g
class CBase
{
public:
virtual long mightBeOverridden(int i) { return 0; } // not a pure
virtual function, since sub-classes should not have to define it
bool isFunctionOverRidden() { return false; }// This is what I want
to code
virtual int id()=0; // this class is an abstract class because of
this function - I don't think that this is relevant but more info is good
};
class CDerived1
{
// Does not override the function
int id() { return 1; }
};
class Derived2
{
long mightBeOverridden(int i) { return i; }
// Should not have to also override isAboveFunctionOverRidden()
int id() { return 2; }
};
class Derived3
{
long mightBeOverridden(int i) { return i * i; }
// Should not have to also override isAboveFunctionOverRidden()
int id() { return 3; }
};
int foo(CBase* pObj, int i, int j)
{
if(pObj)
{
if(pObj->isFunctionOverridden())
return mightBeOverridden(i);
}
return j;
}
I googled on this and came up with nought, as did a search of this list.
I'm guessing that means it's impossible. I thought that I might
compare function pointers ( return mightBeOverridden !=
CBase::mightBeOverridden ) but that doesn't distinguish between the two.
If it's relevant, I'm using MS Visual C++ 7.0 (aka .NET 2002), due to
upgrade to 8.0 soon.
Thanks in advance,
Stewart