+ 2
is there any keyword in c++ like the "final" keyword in java?
5 Réponses
+ 10
Yeah 'const'
In C++ marking a member function const means it may be called on const instances. Java does not have an equivalent to this. E.g.:
class Foo {
public:
void bar();
void foo() const;
};
void test(const Foo& i) {
i.foo(); //fine
i.bar(); //error
}
In both Java and C++ member variables may be final/const respectively. These need to be given a value by the time an instance of the class is finished being constructed.
source and if you want more check:
https://stackoverflow.com/questions/4971286/javas-final-vs-cs-const
+ 3
Yes "const"
+ 3
thanks guyzz
+ 3
The const keyword in C++
There is also a final keyword in C++ but it does different things.
+ 2
Syed Afrid Ali welcome bro..
good luck 💙