我如何在c++的一个类中实现两个同名的函数
How can I implement two functions with same name with in one class in C++?
我有两个同名但参数不同的void函数。代码没有编译。我正在使用eclipse进行编译。
注意:这里我正在寻找覆盖函数。问题解决了。
如何在一个类中实现两个同名的函数C ?
c++有C以外的类。
使用方法/函数重载:
class MyClass
{
void method1(int x) {}
void method1(int x, int y) {}
void method2(int x) const {}
void method2(int x) {}
void method3(int x) {};
void method3(int x, int y = 1) {}; // ERROR ambiguity! when .method3(1)
};
注意,除了参数和限定符的签名,其他都是一样的
相关文章:
- 为什么在排序链表上的这种合并实现总是将两个列表都设置为 NULL,而只有一个应该设置一个列表?
- C++哈希表中,两个相同的实现,但一个给出错误
- 如何将这两个函数组合成一个实现?
- 如何实现对参数顺序不可知的std::same_as的广义形式(即对于两个以上的类型参数)
- std::list 的两个 insert() 方法签名之间的实现差异
- 为什么<T> LLVM 中的预期为 Expect&&... 实现两个构造函数<T>?
- 为什么我们不能同时实现两个方法'getAB() &&'和'getAB()'?
- 在C++中实现两个大小相等的排序数组的中位数
- 模板化成员函数能否实现两个基类的虚函数?
- 如何使用C 中的共享/弱指针清洁实现两个对象
- 如何实现两个类以自动决定深层和浅层复制
- C++堆栈实现 - 两个版本的 top 方法
- 实现两个名称相同但由于多个抽象基类而不同的非协变返回类型的函数
- 快速实现两个 8 位数组的协方差
- 如何用C++在同一窗体中实现两个相同的OpenGL UserControl
- 我如何在c++的一个类中实现两个同名的函数
- 通过实现两个不同于const的函数来避免代码重复
- 如何实现两个可以相互访问的结构体
- 如何实现两个线程的并发
- 用C++实现两个类层次结构的双重调度