메소드 오버로딩

1 개요[ | ]

function overloading, method overloading
함수 오버로딩, 메소드 오버로딩; 오버로딩, 함수 오버로드
  • 함수 이름은 같지만 매개변수, 리턴타입 등이 다른 함수를 쓸 수 있는 기능
  • 한 클래스 내에 같은 이름의 메소드 여러 개 만들 수 있음 (단, 매개변수가 달라야 함)
  • 지원 언어: Ada, C#, C++, 자바 등 다수

2 예시[ | ]

#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);
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}