Program Not Reading Function Declaration

Hi, I'm writing a program for class that requires the use of two .cpps and two .h files. I can get the main file (main.cpp) to read the function declaration header (funhead.h), but not the function definition file (fundef.cpp).

I've been trying to work out the structure of this code before filling in the details, so some things are very simple. All files are in the same directory.

Here are the relevant sections:

1
2
3
4
5
6
7
8
9
10
11
12
//funhead.h
#include <iostream> // all libraries needed for main and fundef
#include <stdio.h>
#include <stdlib.h>
#include <string>

#ifdef funhead
#define funhead

void fun_newcourse(); //adds a new course

#endif 

1
2
3
4
5
6
7
8
//fundef.cpp
#include "funhead.h"
using namespace std;

void fun_newcourse()
{
	cout << "Function not ready yet!";
}

1
2
3
4
5
6
7
8
9
10
//main.cpp
#include "funhead.h"
using namespace std;

int main()
{
	fun_newcourse();

	return 0;
}


When I attempt to compile (using MinGW), it says "error: 'fun_newcourse' was not declared in this scope"

If I move the declaration into main.cpp, the program compiles and the fun_newcourse executes just fine, but I have to put the declaration in a separate .cpp file for this assignment.

What am I doing wrong?
Last edited on
line 7 of funhead.h should be #ifndef funhead (if not defined)
I did this, and now it gives me a different error: "undefined reference to 'fun_newcourse()'
collect2.exe: error 1d returned 1 exit status"
Thank you!
Topic archived. No new replies allowed.