Re: AW: [Dev-C++] Class definition across multiple files and general wrapper class design
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-09-21 09:17:52
|
When building libraries, the linker can not select individual functions/variables that are referenced by the application. It always includes complete object files from the library. Because of this, a good library is modular, with a lot of small object files to not require linking of more functions than what the application need. The same concept is true for classes. If creating really large classes, it might be an id=E9a to split the class implementation into multiple object files to allow an application to only link relevant portions. However, often it is possible to instead split the class into a hierarchy or by sending functor objects or similar as arguments to the methods. /Per W On Tue, 21 Sep 2004, Wehrli, Lior wrote: > > Hi Scott, > > > In learning OpenGL, I have decided to write my own small wrapper class > > that provides me basic funcitons like setting up a window and so forth > > to speed up the learning process. I have begun to write the wrapper > > class, but have several questions: > > Have a look at GLUT, that library offers functions for all the standart w= indow handling and interfacng stuff you normaly need. > > > 1. Can I span the class definition across multiple files, or must I > > stich to the decleration in one .h file and the definition in a .cpp f= ile? > > You can use as many .cpp files as you want, but you can not span the decl= aration of a class over several files. Consider that a class should form an= abstract entity that makes sense, i.e. all its member methods and properti= es should somehow belong together. > > > 2. I have heard some people say you should only define one function per > > .cpp file in a library due to size issues. Is this true, and if so, is > > it worth the added effort? > > I have never heard that. It doesn't matter for the compiler where a funct= ion implemented or how many functions are implemented in a single file. You= can put in a .cpp file what ever you want. The question is more: what make= s sense? Usually the one .h and one .cpp per class is the best choice. > > > 3. What is the level of documentation required for a basic wrapper > > class? I stick to a header at the top of each file, function headers, > > and in code comments. Will it be necessary to include any external > > documentation at this point? > > That is greate. I wish I could force myself to this level of documentary = discipline. If the code is for your own use only, this should be more than = enough. > > > 4. Should I just use several functions in a namespace instead of a clas= s > > to simplify the development process? > > Class vs namespace is not a question of simplification but of design logi= c. If you hav several funtions which are often used together and/or in conj= unction you should use a namespace. If you have several functions which wor= k with the same data structures you might want to wrap the functions and th= e data into a single class. > BTW: A namespace CAN (and should) be spanned over several files. > > > 5. Are there any long term pros/cons associated with maintanence of a > > class versus functions in a namespace? > > Can't think of one right now. I would use both anyway. > > Bye, > Lior > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > Project Admins to receive an Apple iPod Mini FREE for your judgement on > who ports your project to Linux PPC the best. Sponsored by IBM. > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |