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: Wehrli, L. <we...@st...> - 2004-09-21 07:46:27
|
=20 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 = window 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 = file? You can use as many .cpp files as you want, but you can not span the = declaration 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 properties 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 = function 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 makes 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 = class > to simplify the development process? Class vs namespace is not a question of simplification but of design = logic. If you hav several funtions which are often used together and/or = in conjunction you should use a namespace. If you have several functions = which work with the same data structures you might want to wrap the = functions and the 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 |