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?
- It can access only other static members of its class.
- It can be called using the class name, instead of objects.
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.
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;
}
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.
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers