I am doing an exercise (from the third chapter, Thinking in C ++), but I have a problem with two .cpp files.
This exercise:
Create a header file (with the extension '.h). In this file, declare a group of functions by changing the argument lists and return values ββfrom the following: void, char, int and float. Now create a .cpp file that includes the header file and creates the definitions for all these functions. Each definition should simply print the function name, argument list, and return type so you know what it was called. Create a second .cpp file that includes your header file and defines int main () containing calls to all your functions. Compile and run your program.
I created three files, but when I try to compile the compiler give me this error:
undefined reference to `func1 () '
undefined reference to `func2 (int) '|
undefined reference to `func3 (char, int, double) '|
undefined link to `func4 () '|
|| === Assembly completed: 4 errors, 0 warnings === |
Why can't he find the function declaration?
## EDIT
These are my three files:
func_ex.h
void func1(void);
int func2(int i);
char func3(char c, int i, double d);
float func4(void);
func_ex.cpp
#include "func_ex.h"
using namespace std;
void func1(void) {
cout << "void func1(void)" << endl;
}
int func2(int i) {
cout << "int func2(int i)" << endl;
}
char func3(char c, int i, double d) {
cout << "func3(char c, int i, double d)" << endl;
}
float func4(void) {
cout << "func4(void)" << endl;
}
func_ex_main.cpp
#include "func_ex.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
func1();
int i;
func2(i);
char c; double d;
func3(c, i, d);
func4();
}
I use GCC as a compiler (and Code :: Blocks as an IDE, but I think it doesn't matter).