CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: static function

  1. #1
    Join Date
    Feb 2011
    Posts
    32

    Unhappy static function

    What is the role of a static member function ?

    In case I don't know about static stuff, will declaring and using an ordinary member function offer the same result ?

    class CLASS
    {
    public :

    static void func();
    };

    and

    class CLASS
    {
    public :

    void func();
    };

    Would you mind show me significant differences between the use of both in terms of
    1. linking,
    2. storing,
    3. compiling
    4. functioning


    Thank you

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: static function

    To put it short, the major advantage of a static member function is that you don't need an instance of your class (i.e. a concrete object) to call it on. However, this also brings along the major disadavantage: As you don't have an associated object you can't (directly) access any non-static class members from a static member function.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: static function

    A static method is basically a function which is closely associated with the class (possibly even private to it), but which does not directly manipulate an object of the class type.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured