When to use explicit keywork for class construct
来源:互联网 发布:bluehost php版本 编辑:程序博客网 时间:2024/06/08 05:52
/*
* File: main.cpp
* Author: qzhao
*
* Created on 2011年7月2日, 上午8:12
*/
/*
* 对构造函数,进行显示声明,是为了避免隐式转换,
*
*/
#include <iostream>
#include <string>
using namespace std;
class A {
public:
explicit A() : value(0) {
}
private:
int value;
};
void doSomething(const A& objA) {
}
class B {
public:
explicit B(int a = 1, int b = 2) :
m_a(a), m_b(b) {
}
private:
int m_a;
int m_b;
};
void doSomething(const B& objB) {
}
class C {
public:
explicit C(int c) :
m_c(c) {
}
private:
int m_c;
};
void doSomething(const C& objC) {
}
/*
*
*/
int main(int argc, char** argv) {
A a;
doSomething(a);
B b(10);
doSomething(b);
doSomething(B(10));
doSomething(C(10));
return 0;
}
* File: main.cpp
* Author: qzhao
*
* Created on 2011年7月2日, 上午8:12
*/
/*
* 对构造函数,进行显示声明,是为了避免隐式转换,
*
*/
#include <iostream>
#include <string>
using namespace std;
class A {
public:
explicit A() : value(0) {
}
private:
int value;
};
void doSomething(const A& objA) {
}
class B {
public:
explicit B(int a = 1, int b = 2) :
m_a(a), m_b(b) {
}
private:
int m_a;
int m_b;
};
void doSomething(const B& objB) {
}
class C {
public:
explicit C(int c) :
m_c(c) {
}
private:
int m_c;
};
void doSomething(const C& objC) {
}
/*
*
*/
int main(int argc, char** argv) {
A a;
doSomething(a);
B b(10);
doSomething(b);
doSomething(B(10));
doSomething(C(10));
return 0;
}
- When to use explicit keywork for class construct
- When to use Class.isInstance() & when to use instanceof operator
- When to use static method in a java class
- When to use DMU?
- When to use AtomicReference?
- Use GridProjection to construct surface
- Cannot insert explicit value for identity column in table 'settings' when IDENTITY_INSERT is set to OFF.
- Cannot insert explicit value for identity column in table 'settings' when IDENTITY_INSERT is set to OFF.
- Cannot insert explicit value for identity column in table ‘table’ when IDENTITY_INSERT is set to OFF
- Cannot insert explicit value for identity column in table 'TableNa' when IDENTITY_INSERT is set to O
- When to use assert() and when to use try catch?
- An easy-to-use URL file downloader class for .NET
- when to use Java Beans
- msdn:when to use udp
- When to use virtual destructor?
- guard class ,can extend to debug by add errorline number when use this check
- How to use Class class
- When you should use base64 for images
- htc g4 cmwap无法上网cmnet可以上网
- Java日志系统
- Delphi类与对象的概念
- Java多线程编程基础
- opencv 检测直线
- When to use explicit keywork for class construct
- Store加载数据通过监听事件返回加载成功的结果
- 如何深入Delphi编程
- Prefer const, enum ,inlines to #defines
- 试一下新博客
- [MongoDB指导1]Windows下载安装MongoDB
- [MongoDB指导2]Unix下载安装MongoDB
- VMware 完全卸载办法
- [MongoDB指导3]MongoDB基本操作教程