有没有办法防止在编译期间使用未实现的函数?

NoS*_*tAl 0 c++ compile-time

经常我遇到像黑客一样的黑客

//lets say this is some class that still doesnt support...
//...all the functionality that it should based on the design docs
void MyClass::MyFunction()
{
  throw std::exception("not implemented");
}
Run Code Online (Sandbox Code Playgroud)

我想这是一个不好的做法,但除此之外:
有没有办法在编译期间做同样的事情,但只有在使用函数时(如果它是未使用的编译应该成功).

编辑:我也对虚拟内存功能感兴趣.

Eri*_*c B 6

如果完全删除实现并且只有函数声明,则会出现链接器错误,这基本上是编译时间.不幸的是,链接器错误有一种丑陋和难以追踪的倾向,但在调用尚未实现的功能的情况下,我认为它们非常易于管理.

  • 链接器错误不是*基本上*编译时.这是链接时间. (2认同)

Che*_*Alf 5

如果它是非虚拟函数,那么您可以简单地注释掉定义。

如果它是在基类中声明的虚函数,则您无法在编译时控制调用,因此您唯一的选择是某些运行时错误或异常。