Skip to content

Commit 41add26

Browse files
committed
add: cpp-programming-ques 06_operator friend 12
1 parent 79fbf5b commit 41add26

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

06_operator_overloading_and_friend_function/12_overload_subscript.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
// // Overload subscript operator [] that will be useful when we want to check for an index out of bound.
22

3+
/*
4+
5+
In C++, the use of const after the parenthesis of a member function indicates that the function is a const member function. This means that the function does not modify the state of the object on which it is called. The const qualifier is part of the method's signature and is used to enforce the const-correctness of your code.
6+
7+
Here's an explanation of how const is used in the context of member functions:
8+
9+
Const Member Function:
10+
11+
If a member function is declared as const, it means that the function promises not to modify the state of the object on which it is called. This is particularly useful when you have a constant object or a pointer/reference to a constant object.
12+
Const After Parenthesis:
13+
14+
When you see const after the parenthesis, like in void someFunction() const, it indicates that the member function is a const member function.
15+
16+
class MyClass {
17+
18+
public:
19+
void modifyState() {
20+
// This function can modify the state of the object
21+
}
22+
23+
void readState() const {
24+
// This function is a const member function and cannot modify the state
25+
}
26+
};
27+
28+
29+
*/
30+
331
// // Header files
432
#include <iostream>
533
#include <conio.h>

0 commit comments

Comments
 (0)