Hello,
I have wrote a OO program and I have been able to compile ok when using Dev cpp however, I have moved to mac and now compiling through the terminal.
For classes I use a main.cpp (the main script), Numbers.h (The header file for the class) and Numbers.cpp (all the methods)
Numbers.h:
class Numbers
{
public:
Numbers();
Numbers(int theNumber1, int theNumber2);
void setNumber1 (int theNumber1);
void setNumber2 (int theNumber2);
int getNumber1();
int getNumber2();
protected:
int number1;
int number2;
};
Numbers.cpp
#include <iostream>
#include "Numbers.h"
Numbers::Numbers(){}
Numbers::Numbers(int theNumber1, int theNumber2)
{
number1 = theNumber1;
number2 = theNumber2;
}
void setNumber1 (int theNumber1)
{
}
void setNumber2 (int theNumber2)
{
}
int getNumber1()
{
}
int getNumber2()
{
}
Main.cpp:
#include <iostream>
#include "Numbers.h"
int main()
{
Numbers number;
return 0;
}
And I compile using g++ -o main main.cpp (for example)
And it gives me an error like:
Undefined symbols for architecture x86_64:
"Numbers::Numbers()", referenced from:
_main in cczo4aBZ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Any ideas? Really annoying me :(