C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

static methods in class syntax

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Andrew Parker
Guest





PostPosted: Fri Aug 27, 2004 4:51 pm    Post subject: static methods in class syntax Reply with quote



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


Back to top
Victor Bazarov
Guest





PostPosted: Fri Aug 27, 2004 5:08 pm    Post subject: Re: static methods in class syntax Reply with quote



Andrew Parker wrote:
Quote:
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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.