+ 4

why static member function cannot access non static data?

25th Feb 2018, 3:03 PM
Surinder Singh
Surinder Singh - avatar
3 Réponses
25th Feb 2018, 4:57 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
Static member function belongs to the program. Non static members belong to the object. So how is static member function supposed to know, which object's data it us supposed to use, if it doesn't have any notion about objects? If you have 2 objects of a class: A and B, when you call a static member function of that class, which object's data it is supposed to access, if there's by definition one and only one shared static implementation of that static member function?
25th Feb 2018, 3:20 PM
deFault
0
And Do not forget static function can not acess not static directly but if you define an instance then you can use non static members
27th Feb 2018, 11:35 AM
m fatih akıl
m fatih akıl - avatar