I hav a a shared library lib.so
containing a class Foo
. I'm dynamically loading (with dlopen
on UNIX) lib.so
. After loading I want to create an instance of Foo
.
Can I simply use new
operator to create an object of Foo
, or I would have to create an exported factory method placed in lib.so
that will create that object for me?
Actually the question would be if the constructor of Foo
is exported and if it could simply be called with new
operator. I think that all classes and methods within shared library on UNIX are by default exported, and I don't have to export them explicitly as on Windows dll.
Besides hiding the way of creating (and possibly initializing) object of Foo
, are there any other reasons for using the factory method when creating object of class contained in shared library?