C++ Programming - Objects and Classes - Discussion

Discussion Forum : Objects and Classes - General Questions (Q.No. 25)
25.
Which of the following statements are correct for a static member function?
  1. It can access only other static members of its class.
  2. It can be called using the class name, instead of objects.
Only 1 is correct.
Only 2 is correct.
Both 1 and 2 are correct.
Both 1 and 2 are incorrect.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

Eugene said:   3 years ago
Option 1 is incorrect.

Static method can access non-static fields - if it has a pointer to a structure.

Alexander Bedrossian said:   1 decade ago
class my_struct_t{
public:
static void print(){
cout << "Static Print" << endl;
}
};

int main(int argc, const char * argv[]) {

my_struct_t::print();

return 0;
}

Bhanu said:   1 decade ago
Static function can be access or called directly by using class name and (::) scope resolution operator.

Apurwa Pawar said:   1 decade ago
But static function can be call with object in C++.

And in C# it is not allowed.

Aakash said:   1 decade ago
It can access static members of its class directly but non static members with the help of a class object.
(1)

Post your comments here:

Your comments will be displayed after verification.