DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    novice Guest

    static member functions


    What is the purpose in life of static member function?
    I read somewhere that they deal with the static variables in the class.
    But can't we deal with static data members from within non-static member
    functions?

    Thank you

  2. #2
    Rinesh Kumar Agnihotri Guest

    Re: static member functions


    Hello,
    See there can be some good uses that static functions can be put to.
    One of them is to make a singleton class i.e a class which can produce only
    one object and not more.
    It goes like this:
    Supposing that you wish the user of your class to make only one object of
    your class you can make the constructor of your class private and then ask
    the user to call a function which would be a static function and as you know
    that a static func. can be called even before an object is made and hence
    you can implement the logic of the function such that whenever called it
    checks if one object has been made, if it is so then it produces an error
    message or returns the same reference or whatever otherwise it creates an
    object and returns the reference to it.

    I hope this satisfies,
    Rinesh.


  3. #3
    Danny Kalev Guest

    Re: static member functions



    novice wrote:
    >
    > What is the purpose in life of static member function?
    > I read somewhere that they deal with the static variables in the class.
    > But can't we deal with static data members from within non-static member
    > functions?


    static member functions have several uses. The most important one is the
    ability to call them even if no object instance exists. Ordinary member
    function, by contrast, must called on an object. If you don't have an
    object, you can't invoke a nonstatic member function. This feature
    enables static member function to access static data members of a class,
    which as you may already know, exist even if there's no object of that
    class. You can use ordinary members to access static members but
    sometimes you need to access them before you have created the first
    object, for example, in the case of a Singleton or in reference counting
    classes.

    Danny
    >
    > Thank you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links