static member funcction

A

Aneel

I have confusion about 'this' pointer for static member function.
Does the compiler pass 'this' pointer to the static member function.

I have made a class as follows:

class check {
private:
int x;
public:
check():x(0){}
check(int a):x(a){}
~check() {}
void callstatic() {this->print();} // here I am using 'this'
pointer for static member function
// and it is
working..WHY? Since no this pointer is given to static member function
static void print() {cout<<"STATIC";}
};
 
I

Ian Collins

I have confusion about 'this' pointer for static member function.
Does the compiler pass 'this' pointer to the static member function.

No. Static member functions are not associated with an instance of a class.
I have made a class as follows:

class check {
private:
int x;
public:
check():x(0){}
check(int a):x(a){}
~check() {}
void callstatic() {this->print();} // here I am using 'this'
pointer for static member function

This isn't a static member function.
// and it is
working..WHY? Since no this pointer is given to static member function
static void print() {cout<<"STATIC";}

But this is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top