|
![]() |
#1 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2005
Location: ,
Posts: 454
|
![]() Hi, i'm learning the OOP and C++ at home. Now I'm at the Constructor - destructor stuff, and while going thru some exercises i got an error. Now please look at the code and help me. Thanks!
Code:
#include <iostream> #include <conio.h> #include <cstring> using namespace std; class ZnakovniNiz { public: char *pok; ZnakovniNiz(char *p): pok(new char[strlen(p)+1]) { *int i; *for(i=strlen(p)+1;i>=0;i--) * *(pok+i)=*(p+i); }; ZnakovniNiz(const ZnakovniNiz &zn): pok(new char[strlen(zn.pok)+1]) { *int i; *for(i=strlen(zn.pok)+1;i>=0;i--) * *(pok+i)=*(zn.pok+i); }; ~ZnakovniNiz() { delete [] pok; }; }; int main(void) { char strl[]="Tko je taj pokemon?"; ZnakovniNiz PrviNiz(strl); cout<<strl<<endl<<PrviNiz.pok<<endl; ZnakovniNiz DrugiNiz(PrviNiz); cout<<DrugiNiz.pok<<endl; *(DrugiNiz.pok+3)='%'; cout<<DrugiNiz.pok<<endl; cout<<PrviNiz.pok<<endl; getch(); return 0; } At the end of execution i get this problem: ![]() I also know that the program worked fine before creating a destructor.
__________________
Never mess with me when I have a cougar, Never! |
||
![]() ![]() |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
looking for a nice simple but usefull joystick | Juanca | Tech Corner | 20 | 27-11-2008 11:17 PM |
Simple DOS games question..with out DOSBox? | Fubb | General compatibility fixes | 6 | 30-05-2008 11:09 PM |
looking for simple programming exercises? | Koen | Programming | 1 | 15-01-2008 10:52 PM |
|
|
||