青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

每天早晨叫醒你的不是鬧鐘,而是夢想

  C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
  62 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

常用鏈接

留言簿(1)

我參與的團隊

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

ANSI/ISO C++ Professional Programmer's Handbook 》是這樣說的

explicit Constructors
A constructor that takes a single argument is, by default, an implicit conversion operator, which converts its argument to
an object of its class (see also Chapter 3, "Operator Overloading"). Examine the following concrete example:
class string
{
private:
int size;
int capacity;
char *buff;
public:
string();
string(int size); // constructor and implicit conversion operator
string(const char *); // constructor and implicit conversion operator
~string();
};
Class string has three constructors: a default constructor, a constructor that takes int, and a constructor that
constructs a string from const char *. The second constructor is used to create an empty string object with an
initial preallocated buffer at the specified size. However, in the case of class string, the automatic conversion is
dubious. Converting an int into a string object doesn't make sense, although this is exactly what this constructor does.

Consider the following:
int main()
{
string s = "hello"; //OK, convert a C-string into a string object
int ns = 0;
s = 1; // 1 oops, programmer intended to write ns = 1,
}
In the expression s= 1;, the programmer simply mistyped the name of the variable ns, typing s instead. Normally,
the compiler detects the incompatible types and issues an error message. However, before ruling it out, the compiler first
searches for a user-defined conversion that allows this expression; indeed, it finds the constructor that takes int.
Consequently, the compiler interprets the expression s= 1; as if the programmer had written
s = string(1);
You might encounter a similar problem when calling a function that takes a string argument. The following example
can either be a cryptic coding style or simply a programmer's typographical error. However, due to the implicit
conversion constructor of class string, it will pass unnoticed:
int f(string s);
int main()
{
f(1); // without a an explicit constructor,
//this call is expanded into: f ( string(1) );
//was that intentional or merely a programmer's typo?
}
'In order to avoid such implicit conversions, a constructor that takes one argument needs to be declared explicit:
class string
{
//...
public:
explicit string(int size); // block implicit conversion
string(const char *); //implicit conversion
~string();
};
An explicit constructor does not behave as an implicit conversion operator, which enables the compiler to catch the
typographical error this time:
int main()
{
string s = "hello"; //OK, convert a C-string into a string object
int ns = 0;
s = 1; // compile time error ; this time the compiler catches the typo
}
Why aren't all constructors automatically declared explicit? Under some conditions, the automatic type conversion is
useful and well behaved. A good example of this is the third constructor of string:
string(const char *);

The implicit type conversion of const char * to a string object enables its users to write the following:
string s;
s = "Hello";
The compiler implicitly transforms this into
string s;
//pseudo C++ code:
s = string ("Hello"); //create a temporary and assign it to s
On the other hand, if you declare this constructor explicit, you have to use explicit type conversion:
class string
{
//...
public:
explicit string(const char *);
};
int main()
{
string s;
s = string("Hello"); //explicit conversion now required
return 0;
}
Extensive amounts of legacy C++ code rely on the implicit conversion of constructors. The C++ Standardization
committee was aware of that. In order to not make existing code break, the implicit conversion was retained. However, a
new keyword, explicit, was introduced to the languageto enable the programmer to block the implicit conversion
when it is undesirable. As a rule, a constructor that can be invoked with a single argument needs to be declared
explicit. When the implicit type conversion is intentional and well behaved, the constructor can be used as an
implicit conversion operator.
posted on 2011-04-05 18:00 沛沛 閱讀(295) 評論(0)  編輯 收藏 引用 所屬分類: C++
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲人久久久| 亚洲色图自拍| 久久久久免费观看| 欧美制服第一页| 一区二区在线视频| 欧美成人综合| 欧美黑人多人双交| 亚洲综合不卡| 欧美一区二区在线免费观看| 国产一级久久| 欧美激情网友自拍| 欧美日韩久久| 午夜精品久久久久久久久久久久| 久久精品欧洲| 亚洲免费观看高清在线观看| 欧美日韩成人网| 激情av一区| 亚洲国产精品va| 性欧美在线看片a免费观看| 国产综合视频| 欧美在线精品一区| 久久网站热最新地址| 日韩亚洲国产欧美| 一区二区三区毛片| 亚洲大片av| 亚洲调教视频在线观看| 伊人久久大香线| 欧美一级视频精品观看| 久久手机免费观看| 黄色成人免费观看| 一本色道久久88综合日韩精品| 久久国产精品72免费观看| 亚洲福利在线视频| 亚洲主播在线播放| 久久精品二区三区| 国产精品第三页| 久久网站免费| 国产精品久久久久久久9999| 久久在线视频| 国产精品久久久999| 亚洲男人影院| 免费在线成人| 久久婷婷成人综合色| 欧美日韩综合不卡| 亚洲激情网站免费观看| 国产亚洲欧美一区二区三区| 久久久99久久精品女同性| 欧美精品一区二区蜜臀亚洲 | 欧美一区二区久久久| 欧美国产日韩一区二区| 亚洲剧情一区二区| 久久免费黄色| 亚洲伦理精品| 免费不卡亚洲欧美| 久久综合九色欧美综合狠狠| 国产精品午夜在线观看| 宅男精品视频| 激情欧美亚洲| 欧美影院精品一区| 久久国内精品自在自线400部| 欧美一区二区三区精品| 午夜日韩av| 国产精品免费小视频| 99精品欧美一区二区三区综合在线| 国产精品av久久久久久麻豆网| 欧美一级在线播放| 国产精品嫩草久久久久| 一本一道久久综合狠狠老精东影业| 国产欧美日韩在线| 亚洲男女毛片无遮挡| 欧美一级黄色录像| 国产欧美在线观看一区| 午夜日韩av| 久久久99免费视频| 在线看欧美视频| 免费一级欧美片在线观看| 亚洲综合成人婷婷小说| 国产精品久久久久久妇女6080| 久久久久久有精品国产| 韩日精品在线| 久久影视三级福利片| 亚洲高清不卡av| 亚洲深夜av| 国产美女诱惑一区二区| 亚洲国产精品第一区二区| 国产精品稀缺呦系列在线| 性欧美大战久久久久久久免费观看| 亚洲人线精品午夜| 欧美天堂亚洲电影院在线观看| 久久综合伊人77777尤物| 亚洲国产日韩美| 欧美色一级片| 久久国产精品99国产| 午夜精品短视频| 欧美日产国产成人免费图片| 一本久久知道综合久久| 久久久久久久一区二区| 91久久国产自产拍夜夜嗨| 欧美体内she精视频在线观看| 欧美激情中文字幕乱码免费| 国产一本一道久久香蕉| 欧美大片网址| 亚洲欧美国产制服动漫| 欧美国产日韩一区二区| 激情六月综合| 国产精品成人一区二区网站软件 | 亚洲午夜精品久久| 国产亚洲精品一区二555| 亚洲丝袜av一区| 免费永久网站黄欧美| 亚洲影院色无极综合| 亚洲第一精品电影| 国产伦精品一区二区三区在线观看| 99精品99久久久久久宅男| 久久精品一本久久99精品| 亚洲久色影视| 极品尤物久久久av免费看| 久久精品免费电影| 久久综合伊人77777蜜臀| 精品成人国产| 久久字幕精品一区| 亚洲欧美一区二区三区久久| 小黄鸭精品密入口导航| 国产欧美另类| 国产精品jizz在线观看美国| 久久三级视频| 久久成人综合网| 亚洲欧美日韩在线一区| 99在线观看免费视频精品观看| 亚洲无亚洲人成网站77777| 亚洲国产日韩在线一区模特| 欧美成人精品一区二区| 久久九九久精品国产免费直播| 欧美成人按摩| 久久三级福利| 久久久五月天| 久久久久综合一区二区三区| 午夜精品久久99蜜桃的功能介绍| 国产亚洲一本大道中文在线| 国产精品久久激情| 欧美日韩三级在线| 欧美视频免费在线| 欧美日韩一区三区| 欧美日一区二区三区在线观看国产免| 亚洲一区二区免费在线| 在线一区二区三区做爰视频网站 | 亚洲精品国产系列| 亚洲欧洲日本专区| 亚洲美女视频网| 亚洲免费观看高清在线观看 | 亚洲视频在线观看| 亚洲一区二区三区三| 亚洲综合色自拍一区| 亚洲欧美日韩区| 午夜久久福利| 久久精品一区二区三区中文字幕| 亚洲精品国产日韩| aaa亚洲精品一二三区| 亚洲性夜色噜噜噜7777| 亚洲在线第一页| 欧美在线亚洲| 另类天堂视频在线观看| 欧美激情区在线播放| 欧美视频日韩| 国产日韩免费| 亚洲黄色影院| 亚洲在线一区二区三区| 久久精品理论片| 欧美高清视频一区二区三区在线观看 | 欧美成人精品在线播放| 欧美日韩国产小视频在线观看| 欧美制服丝袜第一页| 久久这里只有| 欧美网站在线观看| 欧美成人高清视频| 国产精品video| 黄色资源网久久资源365| 亚洲精品视频免费在线观看| 亚洲一区二区三区精品动漫| 亚洲欧洲三级电影| 午夜久久美女| 欧美大片免费| 美女日韩在线中文字幕| 亚洲免费大片| 亚洲精品欧洲| 久久精品一区四区| 欧美日韩另类一区| 国内成人在线| 亚洲午夜日本在线观看| 免费观看在线综合色| 夜夜嗨一区二区| 亚洲视屏在线播放| 亚洲视频免费| 欧美激情视频在线播放 | 欧美承认网站| 亚洲综合日韩中文字幕v在线| 亚洲一区二区日本| 欧美国产日韩一区二区三区| 国产自产在线视频一区| 亚洲欧美在线一区|