C/C++教程

c++函数忽略某个参数

本文主要是介绍c++函数忽略某个参数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

需求

对于某些函数我们希望再传入多余参数时不做处理
同时我们也不希望不报错,提高兼容性

代码

例如对2D点传入3D坐标进行构造

    /**
     * @brief constructor take x, y, z as parameters where z is nonsense.
     *
     * @note it enables the templated assignment in terms of Point3T
     *
     * @param x x value
     * @param y y value
     */
    Point2T(ScalarType const x, ScalarType const y, ScalarType const /*z*/) noexcept;
这篇关于c++函数忽略某个参数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!