473,545 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 22 '05 #1
1 6519
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::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?


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
8002
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 in "Learning Python" by Mark Lutz and David Ascher. It seems like they are a relatively new feature... It seems to me that any truly OO programming...
33
3316
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 near-impossible. It seems like it would be useful. In fact, there's a place in my code that I could make good use of it. So why not? Chris
6
5762
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
3803
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 experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of...
2
2620
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 members. I want to pass the name of one of the classes to an included file which does some standard operations using those methods and members....
2
1409
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 my app, which basically hold key functionality. For example I have an Asset class. In there I have some methods for getting various attributes of...
5
1798
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 practices? Should I put related C functions into a class and make them static methods? Most of the C functions are in separate files with no global...
13
20750
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 & I don't want to copy + paste code. How can I inherit those member variables? Thanks
14
1623
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 static string ClassName() {
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7413
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7751
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.