Solang said:
I just start learning C++ and have no exeperience with class. I want to
port my C program to C++.
There are too many member functions and I want to split them into
different files.
What is the simplest method to do it?
There are two answers to your inquiry. One is "just do it". Put the
class definition in a header, put the implementation in as many source
files as you like, make sure all files are included in your program,
i.e. compiled and the object modules are linked in. Nothing to it, really.
The other answer is, "review your design". If your class has "too many
member functions", then it's most likely too complex for your own
comprehension, let alone somebody else's come time to maintain it (and
that's immediately after you finish typing it in and compiled it for the
first time). So, you will do yourself and others a huge favor if you
review the design of that class and split it into smaller logical
entities. Once you identified the domains in which each part serves as
the center, you can then combine them by inheriting from all of them
(see policy design paradigm), or by containing them in your class.
Examples of that are too numerous to mention.
Here is one thing you should do, pretty much immediately: find yourself
a good book on C++ design. I recommend works by James Coplien, they
helped me quite a bit. "Modern C++ Design" by Alexandrescu is good, but
can be too "out there" for a beginner. There are probably others, and I
am sure somebody is going to recommend something outstanding.
I can only add at this point: follow the KISS principle (Keep It Simple,
Silly). The tighter the functionality is bundled in each of your types,
the more flexible you can make your system by combining those. Think
Lego: you can make almost anything from a few dozen different blocks by
combining different quantities of them in different ways. Yet each of
them stays extremely simple by itself.
Good luck!
V