Is it ok to use const keyword before the void(or any return type) while declaring and defining the constant method of object? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is it ok to use const keyword before the void(or any return type) while declaring and defining the constant method of object?

Syntax https://sololearn.com/compiler-playground/cMWOIAqZXQYg/?ref=app

16th Feb 2024, 4:43 AM
Yogeshwaran P
Yogeshwaran P - avatar
1 Answer
+ 4
Yes but it does make a difference "myPrint() const" means that the method is const "const void myPrint()" means that the return type is const. Which is anyways meaningless because its void So basically the "const void myPrint()" doesnt make the method constant. It makes the return type
16th Feb 2024, 6:24 AM
Toni Isotalo
Toni Isotalo - avatar