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:
I try to compile this code using the following command: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; }
and I get the following compiler error messages:gcc -o tmp tmp.cpp
However if I compile the above code without the bold line (i.e the following):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
It compiles fine. Its seems to give the above error as soon as I try to use any instance of MyClass.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; }
This may be a trivial problem but I would be grateful for any help.
Thanks.



LinkBack URL
About LinkBacks


