inheritance - Disallow fields in descended class C++ -
With a friend, we recently followed the problem was a base class:
class A {public: A:) foo (10) {} getFoo Virtual Inc () const {return foo; } Conserved: int foo; };
A friend has implemented one class from one class given above.
class B: public A {public: uninterrupted process () {foo = 666; } Preserved: // int foo; }; Unfortunately, he added the field foo to the avatar class (comment line). Then the following code. #include & lt; Iostream & gt; Int main () {A * aaa = NULL; If (1) {B * BBB = new B; BBB- & gt; process (); Aaa = bbb; } Std :: cout & lt; & Lt; Aaa-> GetFoo () & lt; & Lt; Std :: endl; Return 0; }
Print 10 .
This is not a problem, because it will be completely changed, and nothing will happen in the future.
I was just thinking, do you know any portable tricks or patterns of language ( besides clear gates / sets; btw, they were actually there, Foo
TIA!
/ div>
No - you are not concerned about the implementation of the Aadhaar class, therefore you are constrained in the naming of the members Your derivative class and safe data should not be a bad idea
Comments
Post a Comment