Re: querying for virtual method existence
On Jul 12, 6:05 pm, rabin shahav <sha...@gmail.com> wrote:
Hi All,
I've a base class and about 500 derivatives classes. No, i'm not
confusing class instances with class definitions... and don't ask how
we end up having so many classes...
There are few methods which can be eliminated from the whole hierarchy
cone if at run time the base class could "know" if a certain method
was overridden.
Bottom line - i need the code for Foo::wasBarReDefinedNew
your help is well appreciated.
Rabin.
class Foo {
public:
virtual int bar(double, int, char ) ;
virtual bool wasBarReDefined()const=0;
bool wasBarReDefinedNew()const
{ // i need the code here...
return ????
}
};
class Bar1 : public Foo { // about 200 more Bar classes....
public:
virtual bool wasBarReDefined()const{return true;}
virtual int bar(double, int, char );
//....
};
class Baz1 : public Foo { // about 300 more Baz classes....
public: // no override of 'bar'
virtual bool wasBarReDefined()const{return false;}
///....
};
Either I don't understand the question or you answered it yourself
in your post.
Since it looks like all derived classes already implement
wasBarReDefined(), all you have to do is return false
in your Base class's wasBarReDefined.
This way if you invoke wasBarReDefined() on a Base class
object, you'll get false, which is correct. All other cases
will be handled by derived classes' wasBarRedifined().
The real work is, of course, implementing wasBarReDefined for
all your 500+ class, but it seems that you implicated in your
post that it's already been done.
HTH,
Andy.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]