luqingfei@C++

为中华之崛起而崛起!
兼听则明,偏听则暗。

关于函数重载的练习

 

#include <iostream>
#include 
<string>
using std::cout;
using std::endl;
using std::string;

// Function prototype
int plus(int a, int b);
double plus(double a, double b);
string plus(const string& a, const string& b);

void main() {
    cout 
<< "plus(3, 4) = " << plus(34<< endl;
    cout 
<< "plus(3.2, 4.2) = " << plus(3.24.2<< endl;
    cout 
<< "plus(\"he\", \"llo\") = " << plus("he""llo"<< endl;
    
    cout 
<< "plus(static_cast<double>(3), 4.2) = " << plus(static_cast<double>(3), 4.2<< endl;
    cout 
<< "plus(3, static_cast<int>(4.2)) = " << plus(3, static_cast<int>(4.2)) << endl;

}


int plus(int a, int b) {
    
return a + b;
}


double plus(double a, double b) {
    
return a + b;
}


string plus(const string& a, const string& b) {
    
return a + b;
}

posted on 2009-02-13 17:34 luqingfei 阅读(246) 评论(0)  编辑 收藏 引用 所属分类: C++基础


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


导航

<2010年6月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

统计

留言簿(6)

随笔分类(109)

随笔档案(105)

Blogers

Game

Life

NodeJs

Python

Useful Webs

大牛

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜