Skip to content

Tag Archives: C++-Static Keyword

Static Function: It is a member function that is used to access only static data members. It cannot access non-static data members not even call… Read More
Static Function: It is basically a member function that can be called even when the object of the class is not initialized. These functions are… Read More
C++ allows defining static data members within a class using the static keyword. When a data member is declared as static, then we must keep… Read More
Prerequisite : Static variables , Static Functions Write a program to design a class having static member function named showcount() which has the property of… Read More
Prerequisite : Static variables in C Static keyword has different meanings when used with different types. We can use static keyword with: Static Variables :… Read More
Output of following C++ program? #include <iostream> class Test { public:     void fun(); }; static void Test::fun()    {     std::cout<<"fun() is static\n"; } int main() {… Read More
Remain Careful from these two persons new friends and old enemies — Kabir What is static keyword in C++? static keyword can be applied to… Read More
#include<iostream> using namespace std;    class Test { private:     static int count; public:     Test& fun();  };    int Test::count = 0;    Test& Test::fun() {… Read More
Predict the output of following C++ program. #include <iostream> using namespace std;    class A { private:     int x; public:     A(int _x)  {  x =… Read More
Which of the following is true? (A) Static methods cannot be overloaded. (B) Static data members can only be accessed by static methods. (C) Non-static… Read More
#include <iostream> using namespace std;    class Player { private:     int id;     static int next_id; public:     int getID() { return id; }     Player()  {  id… Read More
Predict the output of following C++ program. #include <iostream> using namespace std;    class Test {     static int x; public:     Test() { x++; }     static… Read More
Static keyword is used for almost same purpose in both C++ and Java. There are some differences though. This post covers similarities and differences of… Read More
1) static member functions do not have this pointer. For example following program fails in compilation with error “`this’ is unavailable for static member functions “… Read More
In C++, a static member function of a class cannot be virtual. For example, below program gives compilation error. #include<iostream>    using namespace std;        … Read More