mardi 25 octobre 2016

Force compile time failure if base class virtual function is called?

So I have a class hierarchy along the lines of (no templating):

class BaseClass
{
  virtual bool function_a();
  virtual bool function_b();
  virtual bool function_c();
}

class AClass : public BaseClass
{
  bool function_a() override;
}

class BClass : public BaseClass
{     
  bool function_b() override;     
}

class CClass : public BaseClass
{
  bool function_c() override;
}

I don't want the base functions to be pure virtual as this forces A, B, and C to define each. Is there some way I could have a compile-time error forced if any of the base class functions are called? e.g. If function_b is called on AClass

I attempted a static_assert(false,"") as the default base function call, but this throws the errors at definition time and not when connecting the calls. I would think that the compiler has enough info to know the base is being called, but I don't know how to tap into that knowledge to cause an error.

Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire