General discussion

Locked

Developing a C++ Library

By brewmaster2 ·
Hello all,

Does anyone know of any guidelines on developing a C++ library. I have heard things like "avoid inline code" and "always declare at least one constructor, the copy and assignment constructors and the destructor". I'm sure there are lots of things to watch out for.

Thanks for any tips!

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Good book to help...

by Jeremy6 In reply to Developing a C++ Library

There is a couple of good books that all C++ devleopers need to read in my opinion, "Effective C++" and "More Effective C++" by Scott Meyers. They are not about writing libraries, but they do help you to write solid code, and avoid language pitfalls, which is essential in a library. Both of them are worth checking it out.
They conver some tough topics like inheritance and multiple inheritance, "what functions a compiler silently writes", choosing between function overloading and parameter defaulting, and class and function implementation.

Collapse -

thank you!

by li_ning In reply to Good book to help...

thank you!

Collapse -

C++ Library

by msgwall In reply to Developing a C++ Library

Hi

I guess one of the best tips I got from my mentor a while back is to try to avoid using the aserts in the constructor of an object, this tip leads to a very long conversation but in OO programming you want to allow the object to "be born" and then ask it to do something, if it cannot perform the request let it tell you about it.

Many thanks


Indy

Collapse -

Compiler Independence

by cettech In reply to Developing a C++ Library

A major concern in developing a C++ library, especially for commercial use, is to avoid any dependence on a particular compiler and its associated syntax. Make sure that you don't use any constructs that are not standard C++. Always use STL classes versus other libraries' classes. For instance, don't include MFC classes unless you want to require everyone to use MS Visual C++. There are preprocessor directives or macros that may be specific that you need to avoid. You'll want to test your library with various compilers to see that they work the same. Part of that effort will be to write good test scripts to verify the usage of your library in these different environments.

In the course of your testing with different compilers, you may need to handle situations where a vendor doesn't handle standard C++ and STL correctly. In these cases, you'll have to provide conditional compilation for workarounds.

Even if you use only one compiler right now and are not distributing it for commerical use, it is a good idea to stay as independent as possible with your library so if you ever need to use it elsewhere, you won't have to spend a lot of time integrating it. This approach has saved me hours of time in switching between at least 3 different C++ compilers I use at work.

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums