request for member `push_back' in `((Level*)this)->Level::mapData', which is of non-class type `std::vector<Tile, std::allocator<Tile> >*'|
If I can't figure out what's wrong with this I'll probably try using an array as opposed to a vector as I have a working example of doing it that way. I figured it'd be more of a learning experience if I didn't just copy & paste though
Looking forward to constructive criticism
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
References must be bound to real objects at definition time hence you can
never dynamically allocate an array of references. Also, they cannot be rebound to anything else...ever
Also, references may or may not resolve to run-time entities hidden to the programmer. A reference is almost just another name for the same variable; creating a vector of references is like creating a vector of syntax. You cannot dynamically name variable at run-time, as 'variables' amount to memory storage during execution and 'variable names' are forgotten.
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
So I use . when I wanted to access an object's method and -> when I want to access a pointer to an object's method, right? Well it seems to be working perfectly now that I've changed
Level::~Level()
{
for( int i = mapData.size(); i >= 0; i-- )
{
delete mapData[i];
}
mapData.clear();
writeLog("Map Unloaded from memory\n");
}
How does this look? (I'm doing it backwards because I read somewhere it's better that way although I'm not really worried about order right now unless it matters?)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Level::~Level()
{
for( int i = mapData.size(); i >= 0; i-- )
{
delete mapData[i];
}
mapData.clear();
writeLog("Map Unloaded from memory\n");
}
How does this look? (I'm doing it backwards because I read somewhere it's better that way although I'm not really worried about order right now unless it matters?)
That looks fine. But really you only have to call mapData.clear() it calls the deconstructor(if it has one).
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote:
<sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
dandymcgee wrote:So I use . when I wanted to access an object's method and -> when I want to access a pointer to an object's method, right? Well it seems to be working perfectly now that I've changed
yes, and variables. The reason is that to access a thing in a pointer whit the . operator, you would have to do some thing whit some parenteses(i know it isent spelled corectly, i mean these guys: "( and )") and the * operator. I cant remember how it looks, but i shuold be pretty ugly. Therefore the -> operator was invented.
.:EDIT:.
you said: "a pointer to an object's method"
i dont know what you meant, but you are using it when you want to acces a method(or variable/field) of a object, if the object is a pointer <-- it could probably be described in a better way, but i am not that good at english.
Level::~Level()
{
for (vector<Tile*>::iterator i = mapData.begin(); i != mapData.end(); ++i)
{
delete (*i);
}
mapData.clear();
writeLog("Map unloaded from memory\n");
}
:) But good job in putting .size() in the initialization statement instead of as the stop condition, lots of new folks put it in the stop condition and then their for loop runs slower than necessary.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
MarauderIIC wrote: But good job in putting .size() in the initialization statement instead of as the stop condition, lots of new folks put it in the stop condition and then their for loop runs slower than necessary.
Arguably by a very tiny amount especially for a loop that small and assuming the compiler doesn't optimise it already whether you are counting from or to 0.
As a personal preference, I don't count to 0 as I find it counter intuitive going backwards unless I am in performance critical code.
On the subject of micro optimisations, if you are using iterators then the code should be:
Level::~Level()
{
vector<Tile*>::iterator endItr = mapData.end();
for (vector<Tile*>::iterator i = mapData.begin(); i != endItr; ++i)
{
delete (*i);
}
//mapData.clear(); // Note: No need to call clear as we are destroying the object that owns mapData
writeLog("Map unloaded from memory\n");
}
This is due mapData.end() returning the iterator by value so using it in condition check of the for loop, means you invoke the cost of the copy constructor being called as well as the function call cost (if the compiler doesn't optimise this out). Again, the performance gain is negligible unless you are in a performance loop.