Results 1 to 5 of 5

Thread: What is static Function in C++?

  1. #1
    Join Date
    Dec 2010
    Posts
    3

    What is static Function in C++?

    Hey guys, I need your help as I am not able to get what is Static function in C++? Whenever I make mind a try to understand this terms but I at last I end up with being disappointing. I have tried it from different books to understand but still my concept regarding is term is not clear. If anyone having any information or knowledge about the query which I have asked then please let me know as I very much keen in knowing this concept. If possible then please make it with an example.

  2. #2
    Join Date
    May 2009
    Posts
    539

    Re: What is static Function in C++?

    Functions may also be declared as static .When declared a static, function may only access other static functions or variables of the same class directly. Static function do not have this pointer. A function if declared as static then class shouldn’t have the other function with same name as non static. Static function will be called by means of class name as,
    class_name::function_name(argument list)

  3. #3
    Join Date
    Apr 2009
    Posts
    488

    Re: What is static Function in C++?

    class Box
    {
    int l,w,h;
    static int k;

    public:
    Box()
    {
    l=9;
    w=8;
    h=7;
    }
    }
    Box::k=0;
    main()
    {
    Box b1,b2;
    }
    The above example illustrates that in this example b1 and b2 are the two objects which share one common variable k.

  4. #4
    Join Date
    May 2009
    Posts
    527

    Re: What is static Function in C++?

    Normally when we are creating object of any class, every object will get its own copy of variable declared in the class. Some time we may want some variable common between numbers of objects. Such variables which are common between numbers of object are declared as static. A static variable will be common between the numbers of objects of that class. When you declare a static variable within a class, you are defining it. All static variables are initialized to zero before the first object is created. Even though it is defined it should be declared outside the class.

  5. #5
    Join Date
    May 2009
    Posts
    637

    Re: What is static Function in C++?

    The static function of a class can be called before creation of the object of the class. The static function can access only static variable of the class. A static variable can be accessed using object name or class name. The scope resolution operator must be used when class name is used to access static data. In C++ you can have this feature of creating an object after the static function of a class is created.

Similar Threads

  1. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  2. Make a static reference to the non-static field
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 11:11 AM
  3. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  4. Passing function parameter and static
    By Banjiji in forum Software Development
    Replies: 3
    Last Post: 27-10-2009, 07:32 PM
  5. Replies: 2
    Last Post: 10-04-2009, 09:36 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,353,588.50949 seconds with 17 queries