User forums > Using Code::Blocks
Header file
(1/1)
rwaves:
Learning C++ and trying to create a header file to add two intergers.
add.h header file looks like this:
#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED
int add(int x, int y);
#endif
main.cpp source file looks like this:
#include <iostream>
#include "add.h"
int main()
{
using namespace std;
cout << "The sum of 3 and 4 is " << add(3, 4) << endl;
return 0;
}
Keep getting error: "In function 'main' undefined reference to 'add(int, int)'. I think my code is OK. Has anyone had trouble with this too? Thank you for your help!!
vdave420:
Nope. You haven't defined the function, merely declared it. You won't be able to link an executable without a corresponding definition for the function.
-dave-
Jenna:
Absolutely unrelated to C::B and therefore violating our forum rules.
Topic locked !!
Navigation
[0] Message Index
Go to full version