質問

I have a few libraries, each one is compiled as DLL and they are used by some apps. I've just develop a class (CLASS_A) inside one of those libraries (LIB_1) which inherits from a class (CLASS_B) existing in another of those libraries (LIB_2) and so, it is compiled to another DLL.

So far, I can't see any clear drawback with this solution. The alternative would be to make a copy of CLASS_A and put it inside LIB2, so CLASS_B can inherit from it, but I would like to avoid that solution since I would like to avoid having 2 different versions of the 'same' base class.

¿Is there any important drawback with inheritance from a class inside a DLL?

Thanks a lot!

役に立ちましたか?

解決

On a design note, there are no real problems. The dependency tree is just a bit more complicated, for example if the main program directly uses both classes A and B:

EXE
 +--------+
 v        v
LIB_1    LIB_2
 |
 v
LIB_2

The major problem is the binary compatibility. Unless you are using pure virtual interfaces, your libs will be inheritable and usable only with executables or dlls made with the same version of the same compiler, with a compatible setup (ie, compatible compiler options).

Along with binary compatibility, dlls usually can have their own heap space. And even with pure virtual interfaces, you need to pay attention to which CRT is used in the dlls (if a dll allocate memory, this and only this dll should deallocate it, thus the same CRT is used for malloc/free).

You can read this SO question and this article for more information. This other article is also a very interessting read when dealing with how to export classes in dlls.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top