[C++] 함수 오버로딩
함수의 중복
#include <iostream>
void function(void){
std::cout<<"function(void) call"<<std::endl;
}
void function(char c){
std::cout<<"function(char c) call"<<std::endl;
}
void function(int a, int b){
std::cout<<"function(int a, int b) call"<<std::endl;
}
int main(void)
{
function();
function('a');
function(1, 2);
return 0;
}
디폴트 매개변수
#include <iostream>
int function(int a=0){
return a+1;
}
int main(void)
{
std::cout<<function(11)<<std::endl;
std::cout<<function()<<std::endl;
return 0;
}
#include<iostream>
int BoxVolume(int length, int width=1, int height=1);
int main()
{
std::cout<<"[3, 3, 3] : "<<BoxVolume(3, 3, 3)<<std::endl;
std::cout<<"[6, 6, def] : "<<BoxVolume(6, 6)<<std::endl;
std::cout<<"[9, def, def] : "<<BoxVolume(9)<<std::endl;
return 0;
}
int BoxVolume(int length, int width, int height)
{
return length*width*height;
}