const限定形参的重载
来源:互联网 发布:龙卷风网络收音机 mac 编辑:程序博客网 时间:2024/06/01 09:22
//int *const p 情况
#include <iostream>
using namespace std;class A {
public:
void func(int *p)
{
cout << "int *p" << endl;
}
void func(int *const p)
{
cout << "int *const p" << endl;
}
};
int main(void)
{
A a;
int c = 100;
a.func(&c);
return 0;
}
输出:
t4.cpp:10:7: error: ‘void A::func(int*)’ cannot be overloaded
void func(int *const p)
^
t4.cpp:6:7: error: with ‘void A::func(int*)’
void func(int *p)
^
此时func函数不可重载,const只是表示p指针不能改变,与指针指向的变量无关;
//const int *p情况
#include <iostream>
using namespace std;
class A {
public:
void func(int* p)
{
cout << "int *p" << endl;
}
void func(const int *p)
{
cout << "const int *p" << endl;
}
};
int main(void)
{
A a;
int c = 100;
const int d = 100;
a.func(&c);
a.func(&d);
return 0;
}
using namespace std;
class A {
public:
void func(int* p)
{
cout << "int *p" << endl;
}
void func(const int *p)
{
cout << "int *const p" << endl;
}
};
int main(void)
{
A a;
int c = 100;
const int d = 100;
a.func(&c);
a.func(&d);
return 0;
}
输出:
int *p
int *const p
此时const与变量有关,表示变量是常量,不可改变
- const限定形参的重载
- const限定的是谁
- const形参重载
- 一、从C到C++(一)bool类型、const限定符、结构体内存对齐、重载、默认值形参
- const形参的函数重载
- const形参的函数重载
- const形参的函数重载
- 函数重载和const形参的函数重载
- const限定符的使用
- const限定符的讨论
- const限定符的使用
- const限定符的作用
- 改变const限定的“常量”
- const限定符的理解
- 类的const限定符
- const 限定
- const限定
- 用 const 限定类的成员函数
- 最理想的正方形
- 中文乱码原因解析
- ETL系统增量抽取方案
- 适合新手了解的GUN/Linux起源
- 【Android Studio安装配置教程】一、安装
- const限定形参的重载
- text控件监听键盘弹出和关闭示例代码
- HDU-2255(KM算法)
- Avatar Badge Button checkBox chip
- [深度学习论文笔记][Recurrent Neural Networks] Visualizing and Understanding Recurrent Networks
- Java篇-File类之常用操作
- H5的新特性
- Android 设计模式实战笔记 工厂方法模式
- 自定义IP里面的各个总线接口的定义