> >Yes, that would definitely work. The other alternative which is
cleaner
> >is to detect when I'm invoking a virtual method defined in a base
class
> >and generate code that casts the object pointer to the base class
type
> >before invoking the method. I've got sufficient type information to
do
> >that, it's just a matter of putting in the effort to implement it...
> >
> >-Mike
>
> Speaking strictly as a C++ guy wouldn't what you're proposing be a
giant
> no-op? Isn't the whole point of virtual methods to give you the
ability
> to
> call derived class methods when using a base class 'this' pointer? So
> wouldn't casting from a derived type 'this' pointer to a base type
'this'
> pointer and then calling a virtual method be the same as just using
the
> derived type?
>
> J.
Yep, it's a no-op from a run-time perspective. But the problem I'm
trying to solve actually manifests as a compile-time error, since C++
overload resolution does not take inherited virtual methods into
account. Basically, if you invoke an overloaded virtual method on a
derived type pointer, and that derived type does not override all of the
overloaded instances of that virtual function in the base class, you can
get a compilation error.
Here's a simple example:
enum T1 { FOO1 };
enum T2 { FOO2 };
struct A {
virtual void bar(T1) { }
virtual void bar(T2) { }
};
struct B : public A {
virtual void bar(T1) { }
};
void error()
{
B b;
b.bar(FOO2); // gives error since compiler cannot find void bar(T2)
in B.
}
There are several subclasses in OSG that satisfy this property. It's
caused a minor headache when generating code to invoke the virtual
functions in those classes.
-Mike
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/