I'm reading a tutorial from learncpp.com now, and I'm trying to create a variable(/pointer) with malloc/new, print it, and delete it.
but, I got this:Code:#include <stdlib.h> #include <stdio.h> int main(int &argc, char **argv) { int *pnValue = (int*) malloc(7); *pnValue = 7; printf("Pointer adress: %p\n", pnValue); free(pnValue); }
and I also tried this:Code:mikalv@mikalv-laptop:~/Projects/CExamples$ gcc testalloc.cpp -o kake /tmp/ccm9ZMkq.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
but this also fail, but with another message.Code:#include <stdlib.h> #include <stdio.h> int main(int &argc, char **argv) { int *pnValue = new int; *pnValue = 7; printf("Pointer adress: %p\n", pnValue); delete pnValue; }
Can someone tell me what I'm doing wrong? and why I get these messages, so I can learn to next time..Code:/tmp/cc0FszjM.o: In function `main': dynamicallocation.cpp:(.text+0x19): undefined reference to `operator new(unsigned int)' dynamicallocation.cpp:(.text+0x43): undefined reference to `operator delete(void*)' /tmp/cc0FszjM.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status



LinkBack URL
About LinkBacks




CornedBee