473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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::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
Jul 22 '05 #1
1 6508
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
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned...
33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
6
by: rlvladbob | last post by:
Hi, I've try to access a static method using an instance instead of a class. public class test{ public static void ShowAText(string ThisText) { System.Console.WriteLine("->{0}",ThisText); }
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
2
by: Rafe Culpin | last post by:
Does anyone please know of a way to access static methods of a class, when the name of that class is held in a variable? I have several classes (PHP5) which all have identically named methods and...
2
by: Steve | last post by:
C# I am new to C#, and new to the whole OO concepts, and so I am sure this is a very stupid question, but I'll ask anyway. When should my methods be static? I have several "Business Objects" in...
5
by: Digital Puer | last post by:
Hi, I've inherited a bunch of C code that needs to be called from a C++ framework, so I thought it would be good to put these C functions into C++ classes for better organisation. What are best...
13
by: learning | last post by:
Hi I have a static class written by other team which encapsulates a database instance. but I need to extend it to incldue other things. I know that C# static class is sealed and can;t be inherited...
14
by: d-42 | last post by:
Hi, Is there any way to make this method inheritable and have it behave appropriately on inherited classes? Using generics? Extension methods? Something else? class baseClass { public...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.