classes question

Started by
10 comments, last by 3dmodelerguy 20 years, 1 month ago
is there a benfit from keeping the class seperate from the member function statement? [edited by - 3dmodelerguy on March 20, 2004 11:29:34 AM]
Advertisement
Other? What was/were the other(s) then?
ok is there any?
hmm...
If you mean is there any benefit from putting the class declarations in .h files and implementations to .cpp files then, yes. Here are two coming to my mind first:
- It''s cleaner (and, after all, the way it''s generally done)
- Reduces compiling time considerably (implementations are compiled once only)
Why''s c# reverted back to having the implementations and declarations in one file then?
I don''t know. I''ve never tried C# but I''d guess it has a different class-importing system (couldn''t find any more suitable word now). In C++, when you #include the headers to cpp files, the headers are just copied to them and then compiled. If you have the implementations in headers they''ll get compiled too -- every time you compile the cpp file. In C# there might be some sort of import statement (?) or some other system which doesn''t include the implementations to every source file...

Man, this post is a mess...
You should, however, weigh the increased compile times against the maintenance times involved in keeping header and implementation files separate.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
If you use VC++ as an IDE, you can hop straight to the method in like 2 clicks anyway.

Another use of keeping them separate is that you can distribute the headrers with a compiled lib, then you''re not giving your source code away.
Rubbish.

There is no benefit in the header/implementation file dichotomy. It is simply a limitation of C and C++''s outdated compilation mechanisms. It could be resolved with a multi-pass compilation and the definition of a per-platform ABI, but the Standards Committee won''t do that, citing the overwhelming volume of existing code that would either be broken or need to be rebuilt.

One day, those limitations will catch up to the languages and (finally) remove them from first contention.
quote:Original post by Oluseyi
Rubbish.

There is no benefit in the header/implementation file dichotomy.


On the contrary, there is a HUGE benefit to doing this. Not least because if you keep implementation out of the header file, it''s SO much easier to see at a glance what a class does by looking at its interface. If I want to know what a class does, I don''t want to scan down the header file 100s of line and try to pick out the member functions, I want to glance at the interface and see how to use it.

This topic is closed to new replies.

Advertisement