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!
In C++: How is a static function differnt than non-static?
http://www.codeproject.com/cpp/FastDeleg...
Reply: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
Reply: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.
Reply: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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment