
29 Mar
2010
29 Mar
'10
12:17 a.m.
Emil Dotchevski a écrit :
There is nothing more encapsulating and more abstract than a basic C interface:
struct foo; foo * create_foo( ..... ); void frobnicate( foo * ); void destroy_foo( foo * );
For such interfaces, the most important thing is to physically decouple the user from implementation details. Templates and classes are useless for that.
There are only two benefits of using C++ even for such C-style interfaces:
1) Use exceptions to report errors.
2) Use shared_ptr instead of relying on users to call destroy.
Or better yet, use destructors...