undefined reference to add(int x, int y) ???

Aug 8, 2013 at 8:33am
undefined reference while trying to forward declear a function (add int x , int y ).... please help , thanks
compiler is dev c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdlib>
#include <iostream>
#include "conio.h"
#include "math.h"

   int add (int x, int y);
float adx(float a ,float b)
{
return a+b;
}
double sqt(float c,float d)
{
  return pow(c,d);
}
int main(int argc, char *argv[])
{
 
    float a;
    float c;
    float d;
    float b;
    
    using namespace std;
    
    cout << "two values" <<  add(3,4) << endl;
    
    cout << "enter value of a" << endl;
    cin >> a;
    
    cout << "enter value of b" << endl;
    cin >> b;
    
    cout << "enter another value" << endl;
    cin >> c;
    
    cout << "enter another value" << endl;
    cin >> d;
    
    cout << "square root of last two values is" << sqt(c,d) << endl;
    
    cout << "sum of first two values is" << adx(a,b) << endl;
    cin.get();
    
    cin.get();
    return EXIT_SUCCESS;
}
Aug 8, 2013 at 8:49am
Where is there the function definition?! Or you think the compiler shall invent it itself instead of you?
Aug 8, 2013 at 8:49am
The linker can't find the definition of add. Where is it?
Aug 8, 2013 at 9:06am
is it the " int add (int x, int y);" line?
Aug 8, 2013 at 9:09am
No that's a declaration. The definition is where you write what the function should do.
Aug 8, 2013 at 9:14am
...... how to change it
Aug 8, 2013 at 9:17am
What are you going to change?! You have to define this function. Nobody knows what it should do except you.
Aug 8, 2013 at 9:22am
it adds 3 and 4
Aug 8, 2013 at 9:28am
Maybe. I do not know beacuse neither me nor the compiler see the function definition.
Stop bla, bla, bla. Define the function!
Last edited on Aug 8, 2013 at 9:28am
Aug 8, 2013 at 9:48am
look at lines 7-10 to how define a function
Aug 9, 2013 at 7:35am
thanks , it finally worked
Topic archived. No new replies allowed.