I'm trying to call a virtual function declared in another class.
I understand that the normal method of creating an instance won't work.
I can't seem to work out the correct method.
Can somebody help?
I understand that the normal method of creating an instance won't work.
What?
Classes have static and and non-static member functions.
The static members are like stand-alone functions: called without an object.
The non-static members are called on object whether they are virtual or not.
If you don't have an instance (of some class that inherits Document_interface), then you cannot call the addLine.
Your line 13 creates an uninitialized pointer. You cannot call anything with such pointer. The pointer must point to a valid object, when you call members (of that object).
My apologies, in my last post it should have said-: "Searching though the program I found this for "addLine", which is declared as a non virtual function.
Thanks to @Repeater, I understand a little more about how to call virtual fuction in another class.
Thanks to all who took an interest.
Actually, assuming Doc_plugin_interface is derived from Document_Interface, it's not. Because void addLine(QPointF *start, QPointF *end) is declared virtual in the base class, it will be virtual in all derived subclasses. So, even though the keyword virtual may not have been used in the Doc_plugin_interface declaration, the function was declared as a virtual function through inheritance.