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 ...
随机推荐
- 【树上莫队】【带修莫队】【权值分块】bzoj1146 [CTSC2008]网络管理Network
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using ...
- 看懂ios命名规则
http://liangrui.blog.51cto.com/1510945/509289/ http://daniellee520.blog.51cto.com/372529/229615
- 英雄pk理解面向对象中的this指针概念
class Hero { public int ATN { get; set; } public int DEF { get; set; } public int HP { get; set; } p ...
- Telnet环境变量
转:http://www.cnpaf.net/Class/Telnet/200408/2.html 当前位置: 网站首页>>协议大全>>TELNET协议>> Tel ...
- cs-Filters
ylbtech-Unitity: cs-Filters HealthcareAuthorizeAttribute.cs HealthcareHandleErrorAttribute.cs Health ...
- 精通JavaScript攻击框架:AttackAPI
多年来客户端安全一直未引起人们的足够重视,但是如今情况发生了急剧转变,客户端安全已经成为信息安全领域的焦点之一.Web恶意软件.AJAX蠕虫.浏览历史暴破.登录检测.傀儡控制技术网络端口扫描以及浏览器 ...
- Python数据整合与数据准备-BigGorilla实例应用
参考文档:http://www.biggorilla.org/walkt/ 一.BigGorilla应用主要步骤 如下图: 二.实例应用 1.数据获取 urllib是非常受欢迎的用于在网络上读取数据的 ...
- win10下将spark的程序提交给远程集群中运行
一,开发环境: 操作系统:win19 64位 IDE:IntelliJ IDEA JDK:1.8 scala:scala-2.10.6 集群:linux上cdh集群,其中spark为1.5.2,had ...
- 基于Spark Mllib,SparkSQL的电影推荐系统
本文测试的Spark版本是1.3.1 本文将在Spark集群上搭建一个简单的小型的电影推荐系统,以为之后的完整项目做铺垫和知识积累 整个系统的工作流程描述如下: 1.某电影网站拥有可观的电影资源和用户 ...
- angular directive 的controllerAs的用法
原文: https://stackoverflow.com/questions/31857735/using-controlleras-with-a-directive --------------- ...