0
Calling Function Without Instance (c++)
I want to call static method with dot operator. How can I do it. class Console{ public: static void WriteLine(string x){ cout<< x<< endl; } }; int main(){ string name = "Mustafa"; Console.WriteLine(name); //I want to call like that Console::WriteLine(name); //but i just can do it like that I mean is there any way to call WriteLine function with dot operator (without instance).
2 Answers
+ 1
The very definition of dot operator is to evoke a method or attribute of a class instance/object and not the class itself.
So, I believe you are just left with the option of declaring your Console class 'static' and using the '::' referencer.
0
No, this is how c++ works.