Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: rwaves on June 01, 2011, 04:55:44 am
-
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!!
-
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-
-
Absolutely unrelated to C::B and therefore violating our forum rules.
Topic locked !!