overload a pure function in plugin interface is crashed.
-
hi guys.
here is my interface for a qplugin:class base{ public : virtual ~basse() = default; virtual int func(int ) = 0; }; class drived:public base{ public : int func(int ) override{ return 0; }; };Now a exe app uses QPluginLoader() to call this plugin is fine.
Then we need to add a new func like this:class base{ public : virtual ~basse() = default; virtual int func(int ) = 0; // OVERRIDE same pure function virtual int func(char,char ) = 0; }; class drived:public base{ public : int func(int ) override{ return 0; }; int func(char a,char b) override{ return 0; }; };BUT WITHOUT compile the exe , we run the exe then it crashed!!
If change it to:class base{ public : virtual ~basse() = default; virtual int func(int ) = 0; // just a new pure function virtual int func2(char,char ) = 0; }; class drived:public base{ public : int func(int ) override{ return 0; }; int func2(char a,char b) override{ return 0; }; };STILL NOT compile exe , calling is OK!!!
SO, Why I define a overload pure function will lead to a crash?
class drive wil hide base::func() and just map to one function? -
hi guys.
here is my interface for a qplugin:class base{ public : virtual ~basse() = default; virtual int func(int ) = 0; }; class drived:public base{ public : int func(int ) override{ return 0; }; };Now a exe app uses QPluginLoader() to call this plugin is fine.
Then we need to add a new func like this:class base{ public : virtual ~basse() = default; virtual int func(int ) = 0; // OVERRIDE same pure function virtual int func(char,char ) = 0; }; class drived:public base{ public : int func(int ) override{ return 0; }; int func(char a,char b) override{ return 0; }; };BUT WITHOUT compile the exe , we run the exe then it crashed!!
If change it to:class base{ public : virtual ~basse() = default; virtual int func(int ) = 0; // just a new pure function virtual int func2(char,char ) = 0; }; class drived:public base{ public : int func(int ) override{ return 0; }; int func2(char a,char b) override{ return 0; }; };STILL NOT compile exe , calling is OK!!!
SO, Why I define a overload pure function will lead to a crash?
class drive wil hide base::func() and just map to one function?@QtTester said in overload a pure function in plugin interface is crashed.:
// OVERRIDE same pure function
virtual int func(char,char ) = 0;This is NOT overriding, but overloading! You just added a new pure virtual method.
"STILL NOT compile exe , calling is OK!!!" - I don't get it. If you can't compile you also cannot run it. Can you please explain better?
And if you get compiler errors: why don't you post those?! -
@QtTester said in overload a pure function in plugin interface is crashed.:
// OVERRIDE same pure function
virtual int func(char,char ) = 0;This is NOT overriding, but overloading! You just added a new pure virtual method.
"STILL NOT compile exe , calling is OK!!!" - I don't get it. If you can't compile you also cannot run it. Can you please explain better?
And if you get compiler errors: why don't you post those?!@jsulm
Sorry, pls let me explain more.- overload is right. i was wrong.
- the plugin project generates a DLL file.
in another exe project, it just use qpluginloader() to load the dll, so if we don't comile exe project, just double click the exe to run, it can still load the dll file,right?
generally speaking, if we just add pure virtual function to the tail of the class, the calling won't be crash, because the virtual function table order is not changed for the uncompiled caller(exe). Unless we change the order,like this:
class base{ public : virtual ~basse() = default; // insert an interface before old one, uncompiled caller will be crash virtual int func(char,char ) = 0; virtual int func(int ) = 0; };- exe call the func() like this pseudo code:
base *obj = drived(); obj->func(2);when overload a new func(char,char), it crash, but if we rename to func2(char,char),it runs fine.
So i doubt the same name 'func' did something I don't know. -
@jsulm
Sorry, pls let me explain more.- overload is right. i was wrong.
- the plugin project generates a DLL file.
in another exe project, it just use qpluginloader() to load the dll, so if we don't comile exe project, just double click the exe to run, it can still load the dll file,right?
generally speaking, if we just add pure virtual function to the tail of the class, the calling won't be crash, because the virtual function table order is not changed for the uncompiled caller(exe). Unless we change the order,like this:
class base{ public : virtual ~basse() = default; // insert an interface before old one, uncompiled caller will be crash virtual int func(char,char ) = 0; virtual int func(int ) = 0; };- exe call the func() like this pseudo code:
base *obj = drived(); obj->func(2);when overload a new func(char,char), it crash, but if we rename to func2(char,char),it runs fine.
So i doubt the same name 'func' did something I don't know.