Based on what you have said, I assume that you've put entire functions/classes in the header files. What you need to do is create a .cpp file for each header. Put the definitions of each function/class in the .cpp files but keep a prototype/declaration for that function in the header.
Example, change this:
1 2 3 4 5
// Someheader.h
void SomeFunction()
{
// Some implementation
}
Logical grouping. For example, implementation for one class and its related non-members is logical to have in one place.
In your case I can only guess that you have four functions and you have declarations for them in header files. If so, you could move implementation of each function to separate source file.
You can compile without 'make', but make makes it easier.
When you type g++ -o foo foo.cpp
the g++ does two things:
1. generate object file foo.o from foo.cpp
2. link foo.o an system libraries into binary foo.
If you had two sources, foo.cpp and bar.cpp, you could do:
1. g++ -c foo.cpp
2. g++ -c bar.cpp
3. g++ -o foo foo.o bar.o
When i tried to separate source files like you said, I got many errors.
Here is one of my header files and the main,, could you show me how can i do it please .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//typ.h
int get_type(const string num)// Return the type of the input value
{
if(num[0]=='B') return 0; // The value is Binary number
elseif(num[0]=='0')
{
if(num[1]=='x' || num[1]=='X')
return 1; // The value is Hexadecimal number
elsereturn 2; // The value is Octal number
}
return 3; // The value is Decimal number
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//main.cpp
#include"toBase.h"
#include"toDec.h"
#include"valid.h"
#include"typ.h"
int main()
{
// Main Code
}
Move the definition of the get_type function from "typ.h" into "typ.cpp" and compile it using g++ -c typ.cpp
In "typ.h" leave just the declaration of the get_type function ie: int get_type(const string num);
Do likewise with any other function definitions you have.
Don't forget to include the appropriate header files. For example, "typ.h" will need #include <string>
I have errors because when I tried to change only one function to source code, I compile the program to see if my changes in the function didn't generate errors .
After your reply " Plover ",,
I convert all the functions then i compile it.