Well, the OP is a C++ newbie and cannot be accused of being too much or too little C-isch, can he?
He's making heavy use of the this pointer though. If I understood you correctly you had a problem with that, didn't you?
Printable View
Or with this little poem,
I strongly believe there is,
an implicit pointer called this.
There must be something this is pointing at,
I pray it is like that.
nuzzle,
you've been here far, far less than me,
but notice how you already have 2 green light reputation and I don't.
that means, you've done something right during your short stay here at the CG,
and that those people were helped by you.
The debate on this thread got little hot, no doubt about it.
But it is in this flame that all of us are forged,
for the reasons too hard to understand and too painful to accept,
to take the next hammering of the blacksmith.
So for the sake of people who might need your help in days to come,
I hope you stick around.
Indeed! The impersonal nature of web-based debate can result in very "thick skin" when compared with face-to-face discussions. Don't take it personally.
I seriously would like a code sample that demostrates the logic of having a pointer that points to the temporary r-value pointer of "this" :S. Of course the op doesn't need to do such a thing. he thinks the "this" is an object and not a pointer to the object itself. If anyone knows c++, they know how "this" is typically implemented. They know that it gets pushed on the stack as a parameter for the member function being called.
like
if( Kid.isChild() ) cout << "Yes" << endl;
would be
if( isChild( &Kid ) cout << "Yes" << endl;
that is psuedo code btw
That code makes sense why you shouldn't copy the address of where the pointers is located( &this ) since it is push on the stack and has limited life scope. It will no longer be valid after the member function is called. This is what Paul meant, i believe, when saying why would you need to do this?? It is just not logical
The op clearly thought that "this" was an object and not a pointer to the object itself :)
Again I seriously would like a code sample by Nuzzle that demostrates the logic of having a pointer that points to the temporary r-value pointer of "this" :S
should beCode:List<PObject*>* tlist = postInits->data2For(type);
PObject** ptrtothis = &this;//non-lvalue in unary '&'
tlist->add(ptrtothis);
alsoCode:List<PObject*>* tlist = postInits->data2For(type);
tlist->add( this )
is redundantCode:TEMPLT void List<t>::add(const t* obj, int len){//len is 1 by default
if(totalSize-objectCount>len){
for(int i=0; i<len; i++){
contents[i+objectCount] = obj[i];
}
}else{
increaseSize(len);
for(int i=0; i<len; i++){
contents[i+objectCount] = obj[i];
}
}
objectCount+=len;
}
<= is the opposite of >, but I used < because it made more sense....Code:TEMPLT void List<t>::add(const t* obj, int len){//len is 1 by default
if(totalSize-objectCount < len) increaseSize(len);
for(int i=0; i<len; i++)
contents[i+objectCount] = obj[i];
objectCount+=len;
}
the original code said totalSize-objectCount > len.., but let's say
(10 - 5 > 5) = (5 > 5) == false. if false, increaseSize( 5 ), but i think it should say
(10 - 5 >= 5) = (5 >= 5) == true. if false, increaseSize( 5 ). I think this is right if the totalSize is the total amount in which the list is allocated to hold?
Maybe I am wrong, but I don't see the full implementation either :)
Also Nuzzle, please relax some. No one here is going to flame you unless you're "very!" incorrect or touch a soft topic :D
Also feel free to correct me if I am wrong, but be sure you understand what I meant :D