C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - Programs (Q.No. 5)
5.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
static int x;
public:
static void SetData(int xx)
{
this->x = xx;
}
static void Display()
{
cout<< x ;
}
};
int IndiaBix::x = 0;
int main()
{
IndiaBix::SetData(22);
IndiaBix::Display();
return 0;
}
Discussion:
8 comments Page 1 of 1.
Satyanarayana said:
9 years ago
Static is related to class only not related to object.
This holds current object reference. Here he used as this -> static member. It leads to compile time error.
This holds current object reference. Here he used as this -> static member. It leads to compile time error.
Anshu said:
10 years ago
'this' pointer can't be used with static function. \'this\' pointer is a constant pointer that holds the memory address of the current object. And as static member functions can be called without any object (with class name) , \'this\' pointer is not available in static member functions.
Prashant sediwal said:
1 decade ago
If a object is created then only this pointer is used.
Lalit kumar said:
1 decade ago
This pointer can not used because of unavailable of object of class and base pointer.
Yogesh said:
1 decade ago
Static function doesn't have static function.
Only non static member function have this pointer.
Only non static member function have this pointer.
Satya Prasad said:
1 decade ago
This pointer is unavailable for static functions.
Kartheek said:
1 decade ago
Guys, Answer is very simple the object is not created for the class.
(this) pointer refers to only specified object when ever you are using the keyword (this) it will search for object.
(this) pointer refers to only specified object when ever you are using the keyword (this) it will search for object.
Gaurav said:
1 decade ago
'this' is unavailable for static member functions.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers