Errors, bugs, questions - page 1677

 
Sergei Vladimirov:
I didn't write anything about opening and closing prices.
Then I must have misunderstood you - sorry.
 

Why an error for private methods?

class CFoo
  {
   private:
   void virtual func(int x) final { }
  };
 
class CBar : public CFoo
  {
   void func(int) { }
  };
 
fxsaber:

Why is there an error for private methods?

Private has nothing to do with it, your function is declared as final and you are trying to override it.

ZS. I tried to compile - the compiler says what the problem is.

 
Sergei Vladimirov:
Private has nothing to do with it, you declare this function as final.
So there are no parent private methods in an inherited class. That's why there shouldn't be any overriding.
 
fxsaber:
So there are no parent private-methods in an inherited class. That's why there shouldn't be any overriding.
Well, hello there.
 
Sergei Vladimirov:
Hello there.
Public inheritance. From the descendant private-methods of the parent are not available, according to the compiler.
 
fxsaber:
Public inheritance. The private methods of the parent are not available from the descendant, according to the compiler.

A private virtual method of a base class cannot be called from an inheritor, but you can override it, which is what you are trying to do.

 
Sergei Vladimirov:

A closed virtual method of a base class cannot be called from an inheritor, but can be overridden.

Thanks, I didn't know that. Something I can't think of where this would be useful. It's very similar to X_Macro. I'll try to put together a similar example to get a better understanding.
 
fxsaber:
I'll try to make a similar example to get a better understanding.

That's a nice touch.

class BASE
{
private:
  void virtual Func() { Print(__FUNCSIG__); }
public:
  void Init() {Func();}
};

class CHILD : public BASE
{
private:
  virtual void Func() { Print(__FUNCSIG__); }
};

void OnStart()
{
  BASE* Base = new CHILD;
  
  Base.Init();
  
  delete(Base);
}

I guess such a construction could come in handy somewhere.

 
fxsaber:
public inheritance. The parent's private-methods are not available from the descendant, according to the compiler.
This can be used to make an analogue of the final keyword, explicitly prohibiting further inheritance.
Reason: