programming error (function overloading)

来源:互联网 发布:大数据與1040 编辑:程序博客网 时间:2024/05/29 16:23

Here is the definition of function overloading:


Function overloading or meth overloading is the ability to create multiple methods of same name with different implementations:


Here is an example, (in C++)

#include <iostream>

// volume of a cube
int volume(int s)
{
    return s*s*s;
}

// volume of a cylinder
double volume(double r,int h)
{
    return 3.14*r*r*static_cast<double>(h);
}

// volume of a cuboid
long volume(long l,int b, int h)
{
    return l*b*h;
}

int main()
{
    std::cout << volume(10);
    std::cout << volume(2.5, 8);
    std::cout << volume(100, 75, 15);
}


then it will shows that the "function overloading";


0 0
原创粉丝点击