How to implement static members and static functions in correct manner ?

Posted on 2005-04-10
Last Modified: 2010-04-01
How to implement static members and static functions in a .hpp and .cpp file to work properly ?

Thanks in advance
Question by:martinmoessner
    LVL 30

    Accepted Solution

    Hi martinmoessner,
    Example code:

    //In your header file (*.hpp)
    class foo
      static int DataMember;
      static void MemberFunc();

    //In your *.cpp file

    #include "foo.h"

    int foo::DataMember = 123;

    void foo::MemberFunc()
      //Your function code here

    David Maisonave :-)
    LVL 30

    Expert Comment

    Why the B grade?

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now