Quick question about WinCC OA's implementation of polymorphism, particularly late binding.
Here's some example code:
Code: Select all
class SuperClass
{
public void print()
{
DebugN("SuperClass");
}
}
class SubClass : SuperClass
{
public void print()
{
DebugN("SubClass");
}
}
main()
{
SuperClass super = new SuperClass();
super.print();
SubClass sub = new SubClass();
sub.print();
SuperClass superSub = new SubClass();
superSub.print();
shared_ptr superSubPtr = new SubClass();
superSubPtr.print();
}
Code: Select all
SuperClass
SubClass
SuperClass
SubClass
The OA Help article for Object Oriented Scripting states:
This definition is pretty well aligned with my understanding of late binding, so I'm confused why my third example is using the 'print' method from SuperClass instead of SubClass.you can pass any derived class to a reference of a base class but the executed function will be used from the passed class (if it exists).
I did notice that I'm able to use a shared_ptr to invoke late binding (superSubPtr).
Could any experts out there help clear this up for me? Is late binding simply not supported in OA? Is a shared_ptr a safe alternative, assuming I appropriately manage memory where necessary?
Thanks!
Eric