Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 26-04-2005, 05:12 PM   #1
NrmMyth
Hero Gamer

 
Join Date: Jan 2005
Location: ,
Posts: 454
Red face

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;
}
The exercise is about an array of characters, there are 2 copy constructors for allocating a new memory and then copying needed stuff, and a destructor for deleting that memory.
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!
NrmMyth is offline                         Send a private message to NrmMyth
Reply With Quote
 


Similar Threads
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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 02:15 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.