Re: [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: ZwiQ <zw...@he...> - 2004-09-21 20:14:19
|
> 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?
Yes you can. I personally prefer to declare one single class (and in
rare cases some friends) in a header file and define their functions one
function per sourcefile, eg.:
// a.h
Class A
{
A();
~A();
MemberOfA(unsigned arg);
}
// a.cpp
A::A()
{ /* source code */ }
// ~a.cpp
A::~A()
{/* source code */}
// memberofa.cpp
A::MemberOfA(unsigned arg)
{/* source code */}
> 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'm not sure but I can imagine that the linker will only link
objectfiles the developer using your class actually uses. In that case
its no only far more clear to use seperate files for each memberfunction
but also more efficient. It probably doesn't matter when you publish
your wrapperclass as a single library though?
> 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?
A header for each file is ok in case of one function per file :o). I
suggest a short description of parameters and use of the defined member.
When a project grows larger and larger you may forget what the purpose
of certain functions and their use exactly was. Function headers will
prevent you from that. I did not look for a satisfying
documentationparser by myself yet, but I think there must be some good
applications around which can parse extern documentation from your
comments like JavaDoc does vor Java.
Latter two questions are better answered by someone with some more
experience. I'll only give my personal considerations.
> 4. Should I just use several functions in a namespace instead of a
> class to simplify the development process?
I suggest using classes mainly for things you can (intuitive) describe
in terms of objects. General functions, nothing to do with certain
objects (probably rare in the context of a OpenGL wrapper class) are
maybe on a better place in a librarynamespace. But hey, I never did
these kind of big projects in C++, maybe someone with more experience? :o).
> 5. Are there any long term pros/cons associated with maintanence of a
> class versus functions in a namespace?
Interesting question. I don't know. I can imagine however that there
are. Anyone?
Regards,
Hielke
|