c++ telescoping constructor is NOT supported until c++11
2024-08-27 03:43:54
Telescoping constructor: see Effective Java 2nd Edition Item 2
If you want to use telescoping constructor but your compiler does not support c++11 standards, you can use default parameter instead, see code snippets 'main.cpp', 'Box.h', 'Box.cpp'.
If your compiler supports c++11 standards, the syntax of telescoping is shown in code snippet 'Box2.h' and 'Box2.cpp', and you might need to use '-std=c++11' parameter when you are compiling your source code.
For now, I'd like to use default parameter.
main.cpp
#include "Box.h" int main()
{
Box box;
box.print();
Box box2();
box2.print();
Box box3(, 'A');
box3.print();
Box box4(, 'A', 1.88);
box4.print();
return ;
}
Box.h
#ifndef BOX_H
#define BOX_H class Box
{
public:
Box(const int &_a = , const char &_b = 'M', const double &_c = 0.99);
~Box();
void print(); private:
int a;
char b;
double c;
}; #endif // BOX_H
Box.cpp
#include "Box.h" #include <iostream> using namespace std; Box::Box(const int &_a, const char &_b, const double &_c)
: a(_a), b(_b), c(_c)
{ } Box::~Box()
{ } void Box::print() {
cout << "a = " << a << ",b = " << b << ",c = " << c << endl;
}
Box2.h
#ifndef BOX_H
#define BOX_H class Box
{
public:
Box(const int &_a, const char &_b, const double &_c);
Box(const int &_a, const char &_b);
Box(const int &_a);
Box();
~Box();
void print(); private:
int a;
char b;
double c;
}; #endif // BOX_H
Box2.cpp
#include "Box.h" #include <iostream> using namespace std; Box::Box(const int &_a, const char &_b, const double &_c)
: a(_a), b(_b), c(_c)
{ } Box::Box(const int &_a, const char &_b)
: Box(_a, _b, 0.99)
{ } Box::Box(const int &_a)
: Box(_a, 'M')
{ } Box::Box()
: Box()
{ } Box::~Box()
{ } void Box::print() {
cout << "a = " << a << ",b = " << b << ",c = " << c << endl;
}
最新文章
- DataList删除操作
- [Machine-Learning] 熟悉Matlab
- socket.io 中文手册 中文文档
- 基站查询接口,基站查询API
- Algorithm | Tree traversal
- Spring中bean的scope详解
- SpringMVC学习系列(10) 之 异常处理
- JavaWeb 输出九九乘法表,三角形,菱形
- excel导入数据库
- HDU1297 Children’s Queue (高精度+递推)
- php的setcookie
- C#数据库连接字符串
- Eclipse plugin web site 发布和版本更新
- ArticleRemoveDelDialog【基于AlertDialog的回收删除对话框】
- Java安装以及环境变量配置
- tab 切换实现方法
- ef 数据库连接字符串加密
- sublime使用技巧总结
- insert into on duplicate key update
- GRE协议
热门文章
- 【分块】bzoj2120 数颜色
- iOS 获取自定义cell上按钮所对应cell的indexPath.row的方法
- 【FTP】java FTPClient 文件上传内容为空,文件大小为0
- C#基础之 派生类
- 解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi
- python的dict如何排序
- WebHelper-SessionHelper、CookieHelper、CacheHelper、Tree
- IP地址后面斜杠加具体数字详解
- linux导入so文件
- 蓝点通用管理系统V13版发布了!