c++ telescoping constructor is NOT supported until c++11
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;
}
c++ telescoping constructor is NOT supported until c++11的更多相关文章
- Effective Java学习笔记
创建和销毁对象 第一条:考虑用静态工厂方法替代构造器 For example: public static Boolean valueOf(boolean b){ return b ? Boolean ...
- Effective Java 学习笔记之创建和销毁对象
一.考虑用静态工厂方法代替构造器 1.此处的静态工厂方法是指返回指为类的对象的静态方法,而不是设计模式中的静态工厂方法. 2.静态工厂方法的优势有: a.使用不同的方法名称可显著地表明两个静态工厂方法 ...
- 《Effective Java》读书笔记
一.引言 1.几条基本规则:(清晰性和简洁性最为重要) 模块的用户永远也不应该被模块的行为所迷惑(那样就不清晰了),模块要尽可能小,但又不能太小 代码应该被重用,而不是被拷贝 模块之间的依赖性应该尽可 ...
- Java高效编程(2) -- Creating and Destroying Objects
Item 1: Consider static factory methods instead of constructors Advantage: One advantage of static f ...
- Effective Java 第三版——2. 当构造方法参数过多时使用builder模式
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...
- design_patterns_in_typescript 学习
https://github.com/torokmark/design_patterns_in_typescript Creational Singleton [A class of which on ...
- 《Effective Java》读书笔记一(创建与销毁对象)
No1 考虑用静态工厂方法代替构造器 静态工厂方法优势: 它们有名称,阅读性增强,如:BigInteger.probablePrime: 不必每次调用它们的时候都创建一个新对象: 它们可以返回原返回类 ...
- Java - 用builder代替构造器
静态工厂和够构造器有一个共同的局限性:遇到大量的参数时无法很好的扩展. 先说说构造器. 其实field不多时重叠构造器(telescoping constructor)是个不错的方法,易于编写也易于调 ...
- STL vector的构造函数和析构函数(2)
原文来自:点击打开链接 译文: public member function vector的构造器:这里我仅仅翻译C++11的,C++98的就不翻译了. 构造器原型: <vector> s ...
随机推荐
- 显示字符 Exercise06_12
/** * @author 冰樱梦 * 时间:2018年下半年 * 题目:显示字符 *1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J ...
- 调试SQLSERVER (二)使用Windbg调试SQLSERVER的环境设置 ------符号文件
http://www.cnblogs.com/lyhabc/p/4184708.html
- delphi杀进程的两种方式
delphi杀进程的两种方式 uint unit Tlhelp32; 第一种:比较简单,根据标题,找到窗口,再找到进程,杀死进程 procedure KillProgram(WindowTitle : ...
- ldr与adr的区别
参考: http://coon.blogbus.com/logs/2738861.html http://hi.baidu.com/for_guanghui/item/73e60bbcc8be15a2 ...
- FL2440 rt3070模块station模式动态获取IP地址
---------------------------------------------------------------------------------------------------- ...
- Vue基础知识总结(一)
一.基本语法: 1.实例化:new Vue({}) 2.el:一定是根容器元素(vue的作用域就是这个根元素内),就是写选择器 data:用于存储数据 methods:定义方法(方法里th ...
- 【日志处理、监控ELK、Kafka、Flume等相关资料】
服务介绍 随着实时分析技术的发展及成本的降低,用户已经不仅仅满足于离线分析.目前我们服务的用户包括微博,微盘,云存储,弹性计算平台等十多个部门的多个产品的日志搜索分析业务,每天处理约32亿条(2TB) ...
- 【IE兼容性】background:transparent IE中Bug,不能选中input输入框,出现这个问题主要是IE8
先解释下,background:transparent,默认在IE上会被解析成 background: none transparent scroll repeat 0% 0% transparent ...
- float过后 高度无法自适应的解决方法
float过后 高度无法自适应的解决方法: 在float层最外面包一层div即可.
- POJ1274:The Perfect Stall(二分图最大匹配 匈牙利算法)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17895 Accepted: 814 ...