954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Concept Clarification

Hai everyone
I need a clarification on the following issue

Why does C++ compiler doesn't allow, to initialize static member function inside a class

And please do tell me about what is meant by initializing a function (member function)

Please help me in getting it clear
thank you

Have a nice day

vddmanikanta
Newbie Poster
13 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

Hai everyone I need a clarification on the following issue

Why does C++ compiler doesn't allow, to initialize static member function inside a class

And please do tell me about what is meant by initializing a function (member function)

Please help me in getting it clear thank you

Have a nice day

I'm not sure I understand what you mean, can you post some example code to show us the problem you're having?

Jas.

JasonHippy
Master Poster
772 posts since Jan 2009
Reputation Points: 590
Solved Threads: 125
 

Hai Jasson

Sorry I dont have code
I just want to know the reason why they have designed language this way.

That gives me fair amount of idea of why and where exactly can I use "static ".

vddmanikanta
Newbie Poster
13 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

>>initialize static member function
>>initializing a function

These two things doesn't mean anything in C++. You don't initialize a function. You initialize an object ( or a variable, whatever you call them).
Things you can do with functions are:
Declare them
Define them
Call them
Overload them
Templatize them
May be more but I just cannot think of them right now.

There is no thing as initializing a function (or member function)

siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

Did you read this already?

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

>>initialize static member function >>initializing a function

These two things doesn't mean anything in C++. You don't initialize a function. You initialize an object ( or a variable, whatever you call them). Things you can do with functions are: Declare them Define them Call them Overload them Templatize them May be more but I just cannot think of them right now.

There is no thing as initializing a function (or member function)

To follow on from this reply if I may, and the original question:

Typically you'd usually use a public static member function as an external interface to your class...
In other words, they can be called from outside of the class and also without there necessarily being an active instance of the class!

For example if you had a singleton object, you'd usually include a public static member function in it's class definition to return a pointer to the one and only instance of the object (which could be stored in the class as a private static object, or as a static object in the class's namespace).

That way if other external classes/objects need to be able to access/use your singleton, they have a means to access it.

Offhand I can't think of any practical examples for protected/private static functions...But I'm sure some of the more experienced programmers on here can expand on this!

Cheers for now,
Jas.

JasonHippy
Master Poster
772 posts since Jan 2009
Reputation Points: 590
Solved Threads: 125
 

Thanks Jason
I got it.

vddmanikanta
Newbie Poster
13 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You