Hi, I am very new to C++ and am trying to get a very small example to work on building a very simple class. The code is as below:
Code:
#include <stdio.h>
class MyClass{
public:
void setNum(int num)
{
number = num;
}
int getNum()
{
return number;
}
private:
int number;
};
int main()
{
MyClass tmp;
tmp.setNum(3);
printf("Your number is %d\n", tmp.getNum());
return 0;
}
I try to compile this code using the following command:
and I get the following compiler error messages:
Undefined first referenced
symbol in file
__gxx_personality_v0 /var/tmp/cc2h4zeU.o
ld: fatal: Symbol referencing errors. No output written to tmp
collect2: ld returned 1 exit status
However if I compile the above code without the bold line (i.e the following):
Code:
#include <stdio.h>
class MyClass{
public:
void setNum(int num)
{
number = num;
}
int getNum()
{
return number;
}
private:
int number;
};
int main()
{
MyClass tmp;
//printf("Your number is %d\n", tmp.getNum());
return 0;
}
It compiles fine. Its seems to give the above error as soon as I try to use any instance of MyClass.
This may be a trivial problem but I would be grateful for any help.
Thanks.