News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Header file

Started by rwaves, June 01, 2011, 04:55:44 AM

Previous topic - Next topic

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 !!