如何从我的类的ceil函数中调用c ++中的ceil函数

Shp*_*tem 1 c++ ceil

我需要委托'ceil'功能.我的类有方法'ceil',它需要返回cpp的本地方法'ceil'.怎么称呼它?

double ceil() {
return ceil();
}
Run Code Online (Sandbox Code Playgroud)

- 这是递归

Jok*_*_vD 5

double ceil() {
    return ::ceil(something); // ceil actually has an argument
}
Run Code Online (Sandbox Code Playgroud)

当然,上面是在类定义中定义方法时; 以下是在类外定义方法时:

double MyClass::ceil() {
    return ::ceil(something);
}
Run Code Online (Sandbox Code Playgroud)

正如评论所暗示的那样,使用std::ceilfrom include <cmath>更好,因为确实::ceil不能保证ceil来自C库.

  • 为了便于携带,你应该使用`std :: ceil`.无法保证将C库的名称转储到全局命名空间中(除非您包含已弃用的C头,否则不应该这样). (2认同)