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

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -