C/C++ 函数重载
2009-09-05 16:48
155 查看
#include <iostream> using namespace std; void test(int i,int j=0) { } void test(int i){} int main() { //test(1); return 0; }
上面的程序编译可以通过,但是在main函数中调用test(1)的时候会出现ambiguous,编译器不知道该调用上面的那个函数。
#include <iostream> using namespace std; void test(int* i){} void test(const int* i){} int main() { return 0; }
上面的程序也可以编译通过,由此可以认为const int*和int*属于不同的类型,但是如果我把程序改成下面这样:
#include <iostream> using namespace std; void test(int* i){} void test(int* const i){} int main() { return 0; }
则编译不通过,因为此时const只是一个修饰符而已。
下面的程序也可以编译通过,并且函数调用的结果是no const function!
#include <iostream> using namespace std; class c { public: void test(int i)const { cout<<"const function!"<<endl; } void test(int i) { cout<<"no const function!"<<endl; } }; int main() { c t; t.test(1); return 0; }
相关文章推荐
- C++ 函数重载(十三)
- 学习笔记:C++ 函数重载
- C++的函数重载
- C++父类与子类关系以及函数重载、覆盖和隐藏规则 http://blog.csdn.net/xingyu19871124/article/details/7640131
- C++中的函数重载
- 编译器如何C++的函数重载
- C++父类与子类关系以及函数重载、覆盖和隐藏规则
- 从零开始学C++之从C到C++(一):const与#define、结构体对齐、函数重载name mangling、new/delete 等
- C++中函数重载、隐藏、覆盖和重写的区别
- C++的函数重载 推荐
- [C++]C++的函数重载
- C++中的引用变量、默认参数和函数重载
- C++的函数重载
- C编程笔录(一)1.3: 为什么C不支持函数重载,而C++支持?
- C++ 编程思想——函数重载与缺省参数
- C++学习日记13——递归、内联、函数重载、变量的作用域和存储类型
- C++ cin.get() 函数重载
- C++函数的高级特性-函数重载
- C++简单的函数重载与函数模板