Question:
In C++: How is a static function differnt than non-static?
K
2007-11-03 09:38:33 UTC
I have to write a program using static functions.

Does the static keyword make the function polymorphic?

Is there a major differance in the way the function is defined?

Please help!
Five answers:
SWEngr
2007-11-03 09:45:41 UTC
http://www.codeproject.com/cpp/FastDelegate.asp
i♥sf
2007-11-03 09:56:51 UTC
No, it's the virtual keyword, applied to functions, that makes classes polymorphic.



The static keyword applied to class methods makes it so that the method can be called at any time (using the class::method() calling convention); you don't have to create an object and dispatch the method off the object. But this also means that your function can't reference any object data unless it's static as well, because it hasn't been instantiated.



Static functions not contained inside a class are merely functions with local scope inside a file.
ali_fakoor
2007-11-03 10:03:17 UTC
Static member functions are unique for the class type and referenced by the class name [not the instances] (They are like global functions). They can only access static member variables /functions of their class.



But non-static member functions are accessed via the instances of the class and can access the non-static member variables / functions of their instances.
abdelrahmaner
2007-11-03 09:52:40 UTC
i don't know but static definition i C#



public static void MyMethod(object aruments)

{



}



how the funcction be polymorphic sorry i don't understand it
2016-12-08 15:50:30 UTC
classification CMyClass { deepest: //information participants, blah blah public: static void MyStaticFunc(void); void MyNonStaticFunc(void); }; void CMyClass::MyStaticFunc(void) { } void CMyClass::MyNonStaticFunc(void) { } simples


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...