Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sharing c++ class



On 11/29/03 3:28 PM, Alexander Cohen wrote:
> So that would be the only way. Its not possible to have a library that
> exports a C++ class?

Technically, the library doesn't export the C++ class. It can export the
member functions and the virtual function table associated with the class.
Everything boils down to either a function pointer or a pointer to some
global data.

You need to include the .h file so clients can compile against the library.
Developers should understand they should not modify the .h file, because the
library depends on the class definitions and inline functions being the same
as when it was compiled.

Developers must compile their code with a compatible C++ compiler, so the
name mangling is the same. In practice, this requires shipping multiple
libraries, for each combination of compiler and the major compile options,
such as debug.

If your C++ class uses the standard template library, the developer must
compile against the same STL headers that your library was compiled with.

If your library is dynamic, there may be issues with object creation. The
class will have its own operator new, which will be pulled in when the
library is linked. An application that uses the library must be careful to
delete objects created by the library using the library's operator delete,
not the application's. Otherwise, objects can be deleted from the wrong heap
and bad things happen. A common solution to this problem is to move operator
new and delete to yet another dynamic library that everyone links against.

Static libraries are easier.

Regards,

Tom

--
Tom Becker "Within C++, there is a much smaller and
Object-Oriented Propeller Head cleaner language struggling to get out."
<email@hidden> -- Bjarne Stroustrup
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: sharing c++ class (From: Alexander Cohen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.