• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

question about C++

z0mb13

Lifer
is there a keyword (or a way) to define a function such that it cannot be redefined in its child classes???

what I mean is like this:

class Upper {
...
public:
int foo(int a);
....
}

class Lower: public Upper {
....
}

i.e class Lower is a child of Upper, I want it so that function foo cannot be redefined in class Lower (and also other child classes)

TIA




 
Unfortunately in c++ there is no such way. In java, you would use keyword final, but this is one of the shortcomings of c++.
 
Originally posted by: Argo
Unfortunately in c++ there is no such way. In java, you would use keyword final, but this is one of the shortcomings of c++.

I'd hardly call it a short-coming. If you make a method public, then it's fair game for any derived classes to redefine it they see fit. If you want to prevent the behavior, then it shouldn't be public in the first place.
 
Back
Top