I think, that if I sit down and really think about this matter, I would be able to solve it, but every time I try it, I get a splitting head ache.
Imagine the following situation:
A class contains a double pointer, that points towards an array of pointers, each and every one of the pointers in the array points towards an object which contains a new double pointer with a new array of pointers that points to a new set of objects.
Now, how would I create a copy-constructor and create an operator overloading for such a construction? ^^
I can work out one double pointer with one array, but at this very moment my brain can't handle one more, so if anyone is good with pointers then a little push in the right direction would be appreciated ^^
Anyway, happy new year!
[C++][Solved]Anyone good with pointers and constructors?
[C++][Solved]Anyone good with pointers and constructors?
Last edited by ayu on 28 Jan 2009, 05:01, edited 1 time in total.
"The best place to hide a tree, is in a forest"
Passed midnight coding is healthy =)
issue has been solved, was rather easy when you look at it now, although not tested yet it looks like it will work, will be tested when the application is test-compiled later ^^
issue has been solved, was rather easy when you look at it now, although not tested yet it looks like it will work, will be tested when the application is test-compiled later ^^
Code: Select all
Engine::~Engine()
{
for(int i = 0; i < mNumCategories; ++i)
{
if(mCategory[i] != NULL)
{
mCategory[i]->~Category;
delete mCategory[i];
}
}
delete [] mCategory;
}
"The best place to hide a tree, is in a forest"
-
- Kage
- Posts: 732
- Joined: 31 Mar 2007, 16:00
- 17
- Location: Hidden in a Buffer Protection.
- Contact:
Bravo cats. I was thinking the same thing, but did you allocate the pointers with "new" ?
Ex:
Ex:
Code: Select all
int *mCategory[] = new int;
[img]http://i81.photobucket.com/albums/j205/ebrizzlez/4lsint1.jpg[/img]
Update:
Didn't work ^^ gives the following error
It would seem as if you can not call a destructor like that. So I will have to make a separate function to do it for me, and I'll update this thread again when I have done so and seen that it works.
Didn't work ^^ gives the following error
Code: Select all
1>Engine.cpp
1>.\Engine.cpp(27) : fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1411)
"The best place to hide a tree, is in a forest"
Sure thing buddy ^^ here is the solutionSwan wrote:Yes cats, would be very grateful if you WOULD post your solution. I am very intrigued now =)
Code: Select all
Engine::~Engine()
{
for(int i = 0; i < mNumCategories; ++i)
{
if(mCategory[i] != NULL)
{
mCategory[i]->EmptyCategory();
delete mCategory[i];
}
}
delete [] mCategory;
}
Code: Select all
void Category::EmptyCategory()
{
for(int i = 0; i < mNumItems; ++i)
{
if(mItem[i] != NULL)
delete mItem[i];
}
delete [] mItem;
}
"The best place to hide a tree, is in a forest"