undefined reference to function
Jul 30, 2017 at 1:44pm UTC
Write your question here.
problem is this code showing undefined reference to decof xora(int,int)
error is showing on this line m= ob.xora(q[j-1],i[j-1]);
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
cpp
#include <iostream>
#include "decof.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
int n,j;
cout<<"How many digits?" <<endl;
cin>>n;
int i[n],p,q[n+1],m;
decof ob;
for (int j=0;j<n;++j)
{ cin>>p;
i[j]=p;
}
for (int j=0;j<n;++j)
{ cout<<i[j];
}
for (int j=0;j<(n+1);++j)
{
if (j==0)
{
cin>>q[j];
}
else
{
m= ob.xora(q[j-1],i[j-1]);
}
}
return 0;
}
header fle:
#ifndef DECOF_H
#define DECOF_H
class decof
{
public :
decof();
virtual ~decof();
int xora(int q,int i);
protected :
private :
};
#endif // DECOF_H
decof function:
#include <iostream>
#include "decof.h"
using namespace std;
decof::decof()
{
//ctor
}
decof::~decof()
{
//dtor
}
int xora(int q,int i)
{
return ((q||i)&&!(q&&i));
}
er
Jul 30, 2017 at 1:52pm UTC
You need to properly qualify that xora() is part of the class and that it is not just a function in the global scope.
int decof::xora(int q, int i)
But really there is not much point of our class since it doesn't have any class member variables.
I also suggest you start using more meaningful variable and function names to make your code easier to understand.
Last edited on Jul 30, 2017 at 1:53pm UTC
Jul 30, 2017 at 1:57pm UTC
Thanks, It works
Topic archived. No new replies allowed.