Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static member funcction

Reply
Thread Tools

static member funcction

 
 
Aneel
Guest
Posts: n/a
 
      04-02-2010
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()(0){}
check(int a)(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";}
};

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      04-02-2010
On 04/ 2/10 06:07 PM, Aneel wrote:
> 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()(0){}
> check(int a)(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.

--
Ian Collins
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a static member function access non-static member? dolphin C++ 3 12-05-2007 12:39 PM
How do you call a regular member function from a static member function? aling C++ 6 10-30-2005 04:38 AM
Can Derived class static member access protected member from base class? Siemel Naran C++ 4 01-12-2005 06:46 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM
performance of static member function vs. instance member function 0to60 C++ 4 11-21-2003 05:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57