Advantage of using a static member function instead of an equivalent non-static member function?
Posted
by jonathanasdf
on Stack Overflow
See other posts from Stack Overflow
or by jonathanasdf
Published on 2010-05-01T05:05:55Z
Indexed on
2010/05/01
6:37 UTC
Read the original article
Hit count: 359
I was wondering whether there's any advantages to using a static member function when there is a non-static equivalent. Will it result in faster execution (because of not having to care about all of the member variables), or maybe less use of memory (because of not being included in all instances)?
Basically, the function I'm looking at is an utility function to rotate an integer array representing pixel colours an arbitrary number of degrees around an arbitrary centre point. It is placed in my abstract Bullet base class, since only the bullets will be using it and I didn't want the overhead of calling it in some utility class. It's a bit too long and used in every single derived bullet class, making it probably not a good idea to inline. How would you suggest I define this function? As a static member function of Bullet, of a non-static member function of Bullet, or maybe not as a member of Bullet but defined outside of the class in Bullet.h? What are the advantages and disadvantages of each?
© Stack Overflow or respective owner