Oct 5, 2013 at 4:09am UTC
Hi guys
here is really simple problem but once i try to compile it , it gives me this error which i really dont get it and couldnt find solution for that:
error: fatal error LNK1120: 1 unresolved externals
and here is my program
file :vector.h
#ifndef vector_h
#define vector_h
class vector
{
double i;
double j;
double k;
public:
vector(double a=0.0,double b=0.0,double c=0.0);
vector operator+(const vector) const;
void printsum();
};
#endif
file 2:vector.cpp
#include "vector.h"
#include <iostream>
using namespace std;
vector::vector(double first,double second,double third)
{
i=first;
j=second;
k=third;
}
vector vector::operator+(const vector d) const
{
vector temp;
temp.i=i+d.i;
temp.j=j+d.j;
temp.k=k+d.k;
return temp;
}
void vector::printsum()
{
cout << "the sum of this two vector are " << endl;
cout << i << " i " << j << " j " << k << " k " << endl;
}
file 3:main.cpp
#include "vector.h"
#include <iostream>
using namespace std;
int main()
{
vector v1;
vector v2(2.00,5.00,7.00);
vector v3(2.00,6.00,8.00);
v1=v2+v3;
v1.printsum();
return 0;
}
Last edited on Oct 5, 2013 at 4:10am UTC
Oct 5, 2013 at 5:41am UTC
Did you add vector.cpp to the to-compile list?
Oct 5, 2013 at 9:28am UTC
Just to clarify MiiNiPaa's answer, if you are using g++ you would have to make sure you do:
g++ -std=c++0x -Wall --pedantic -o my_program main.cpp vector.cpp
I believe in Visual Studio you would have to add vector.cpp/.h to your project.
All the best,
NwN
Last edited on Oct 5, 2013 at 9:29am UTC
Oct 5, 2013 at 7:25pm UTC
thank you so much guyz,it works now