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

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.

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 ".

>>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)

>>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.

This article has been dead for over six months. Start a new discussion instead.