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).

25th Nov 2017, 6:46 PM
Mustafa K.
Mustafa K. - avatar
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.
25th Nov 2017, 7:12 PM
Anil
Anil - avatar
0
No, this is how c++ works.
25th Nov 2017, 7:03 PM
Timon Paßlick