[Just Curious] Reason for using pointers in cocos2dx?

[Just Curious] Reason for using pointers in cocos2dx?
0.0 0


I’ve been wandering why cocos2dx uses pointer for, almost, every cocos2dx variables.
Size, Point…well, let’s not include that are non pointers lol.

Anyways, is this because cocos2dx supports autorelease() and autorelease needed for only pointers?


C++ programming without pointer types sucks. :smiley:

Anyway, do you use auto type? I think it will be of help to you.


In Cocos2d-x guide they said not to use pointer for cocos2d::Vector type


You usually want to use pointers for things that you want to keep in the heap, so that you can pass the pointer around and retain/release/autorelease it when needed. That is the reason why Director, FileUtils etc. are always pointers. Points are sometimes held in vectors in cocos2d-x (found 2 places in source code), so they are allocated in heap instead of stack (they would be deleted at the end of current scope). Also Point* is being passed to some functions so that the function can store result in it or it is used as a pointer to the first element of Point array.
PS. Haven’t seen any place in the code where Size is stored as pointer.


@dalinaum I heard C++ is super important with memories. Btw, I have your game lol. I play few times before going to bad.


@chulman444 Thank you very much. Have a nice night.