12 events
when toggle format what by license comment
May 11, 2021 at 9:04 comment added underscore_d (At least in some languages, e.g. C++...) Static member functions can access private members of instances passed or otherwise accessible to them. Thus "use static functions when they don't depend on any class members" is not the best advice, because the functions still in theory can mess with internals of instances, which can lead to surprises. If the function really doesn't need such access, it should be a non-member free function (if your language supports that, which I hope it does!), so it can never end up overstepping its mark.
Apr 3, 2021 at 19:12 comment added Bernard @huangzonghao Not clear on what you are asking. Can you please provide an example of what you mean?
Apr 1, 2021 at 17:07 comment added hzh @Bernard if a function defined in a namespace does the job you described, then what's the point to define a class and use static methods.
Nov 4, 2020 at 19:09 comment added Bernard @Milan How do you differentiate "functions" and "static methods"?
Nov 4, 2020 at 1:49 comment added Milan We already have functions then why the concept of static methods still exists? I mean we use the static methods as same as we use the functions, right? then what is the need for static methods? Sorry if I'm mistaken or my question is too basic. Thanks a lot in advance :)
Aug 22, 2013 at 18:47 history made wiki Post Made Community Wiki by newprint
Aug 21, 2013 at 13:32 comment added Bernard @newprint: You are correct, however that is not what I said. I said when they don't depend on any class members. Using static members is fine if they are necessary, but that may not always be the case.
Aug 20, 2013 at 23:48 comment added newprint I have a slight problem with your definition "they don't depend on any class members". Member static functions can't access any non-static member, however they can access static members. Static members are members of the class.
Oct 23, 2011 at 18:35 vote accept Dark Templar
Oct 10, 2011 at 17:19 comment added Bernard @Dark Templar: Can't say that I do. Is this specific to a particular language?
Oct 8, 2011 at 22:01 comment added Dark Templar Thank you Bernard. Btw, do you know what it means for a compiler to "bind a method to the class"?
Oct 7, 2011 at 18:15 history answered Bernard CC BY-SA 3.0