![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 239
Rep Power: 3
![]() |
Quote:
![]() As for the header files, I have already made all these things, and had created separate files, but until my problem was fixed, I thought it would be good to put all those things into one file, for the users in here to read it all-in-one. Thanks for the advice anyway.
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
|
#12 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#13 | ||
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 239
Rep Power: 3
![]() |
Quote:
//--reset the stash
void stash::clearStash(){
delete [] ch;
ch = new char [gIncrement];
currentSize = 0;
currentStorage = gIncrement;
next = gIncrement - currentSize;
}int main(){
stash o("hello world");
stash b;
b = o;
o.show();
b.show();
return 0;
}Quote:
What went wrong?
__________________
Project::Soulstorm (personal homepage) |
||
|
|
|
|
|
#14 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 239
Rep Power: 3
![]() |
edit: I found it. It was stupid. I think I will turn off the computer now...
![]()
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
#15 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Ouzo time, eh?
![]()
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#16 | |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 239
Rep Power: 3
![]() |
Quote:
![]()
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
|
#17 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Beats the hell out of Miller!
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#18 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 824
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#19 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 239
Rep Power: 3
![]() |
Of course. I don't have the code in front of me, but i remember that the problem resided in the clearstash() function. When I was deleting the 'ch' pointer, I didn't make sure wether that pointer was allocated or not. The result was in some occasions the compiler to give me warnings and errors (when the 'clearstash()' function was called before a string allocation was made).
The solution was to pass the 'ch' pointer a zero value at the beginning (in my constructors), then with an 'if' statement, make sure every time I call 'clearstash()' the 'ch' pointer is allocated before deallocation. That could be done like this, if I remember correctly: void stash::clearStash(){
if(ch)
delete [] ch;
ch = new char [gIncrement];
currentSize = 0;
currentStorage = gIncrement;
next = gIncrement - currentSize;
}
__________________
Project::Soulstorm (personal homepage) Last edited by Soulstorm; May 27th, 2006 at 2:23 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|