static methods in class syntax

Discussion in 'C++' started by Andrew Parker, Aug 27, 2004.

  1. Hi, I'm having a syntax problem and hours of googling has yet to reveal a
    solution.
    I'm writing a class that contains only public static methods. It's a class
    of useful misc. functions that don't require any variables.
    So i'm writing in my header file:

    class Helper {

    public:
    static int helperOne();
    static void helperTwo();
    etc...

    };

    and in my .cpp file I'm writing:

    static int Helper::helperOne(){
    //some code
    }

    static void Helper::helperTwo(){
    //some more code.
    }

    But the compiler is complaining that I can't declare static methods at the
    file scope level. I found some examples of declaring static methods on the
    net, but they all did all the method declarations and definitions at the
    same time in the header file and I want to split the definitions off into a
    ..cpp file for cleanliness sake. Can anyone correct my syntax here?
    ~Andrew
    Andrew Parker, Aug 27, 2004
    #1
    1. Advertising

  2. Andrew Parker wrote:
    > Hi, I'm having a syntax problem and hours of googling has yet to reveal a
    > solution.
    > I'm writing a class that contains only public static methods. It's a class
    > of useful misc. functions that don't require any variables.
    > So i'm writing in my header file:
    >
    > class Helper {
    >
    > public:
    > static int helperOne();
    > static void helperTwo();
    > etc...
    >
    > };
    >
    > and in my .cpp file I'm writing:
    >
    > static int Helper::helperOne(){
    > //some code
    > }
    >
    > static void Helper::helperTwo(){
    > //some more code.
    > }
    >
    > But the compiler is complaining that I can't declare static methods at the
    > file scope level. I found some examples of declaring static methods on the
    > net, but they all did all the method declarations and definitions at the
    > same time in the header file and I want to split the definitions off into a
    > .cpp file for cleanliness sake. Can anyone correct my syntax here?


    Drop the 'static' when defining the functions.

    Victor
    Victor Bazarov, Aug 27, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo
    Replies:
    1
    Views:
    515
    Scott Allen
    Jan 7, 2005
  2. SaravanaKumar
    Replies:
    6
    Views:
    9,386
    Tony Morris
    Oct 19, 2004
  3. Oliver Wong
    Replies:
    14
    Views:
    1,608
    Chris Uppal
    Jun 13, 2006
  4. Oltmans
    Replies:
    6
    Views:
    339
    Terry Reedy
    Mar 11, 2009
  5. Kenneth McDonald
    Replies:
    5
    Views:
    311
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page