I have been learning C++, and have been using some test code to debug pieces of a much larger project. I am trying to use an object from another file, but I keep getting an undefined reference error despite having included the appropriate header file. I am using Eclipse with the C++ CDT on Linux. The code looks something like the following:
A.cpp
class A {
private:
int i;
int j;
public:
A(int i1, int i2) {
i = i1;
j = i2;
}
int sum() {
return (i+j);
}
};
a.h
#ifndef A_H_
#define A_H_
class A {
public:
A(int i1, int i2);
int sum();
};
#endif
main.cpp
#include <iostream>
#include "a.h"
int main() {
A a(1,2); //undefined reference to 'A::A(int,int)'
std::cout << a.sum(); //undefined reference to 'A::sum(void)'
return 0;
}
Is this a problem with my syntax, or do I need to go digging around in the compiler?