static methods in class syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Parker

    static methods in class syntax

    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::helperO ne(){
    //some code
    }

    static void Helper::helperT wo(){
    //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


  • Victor Bazarov

    #2
    Re: static methods in class syntax

    Andrew Parker wrote:[color=blue]
    > 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::helperO ne(){
    > //some code
    > }
    >
    > static void Helper::helperT wo(){
    > //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?[/color]

    Drop the 'static' when defining the functions.

    Victor

    Comment

    Working...