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

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

  C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
  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 沛沛 閱讀(290) 評論(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成人免费| 欧美激情视频一区二区三区免费| 狂野欧美一区| 国产一区二区三区在线观看视频| 亚洲午夜一区二区| 亚洲一区二区成人| 欧美日韩成人在线| 亚洲美女网站| 一区二区三区精品| 欧美日本精品一区二区三区| 亚洲片国产一区一级在线观看| 伊人久久综合97精品| 久久精品盗摄| 欧美成人高清| 亚洲电影第三页| 久久成人亚洲| 免费欧美视频| 亚洲精品久久久久久一区二区| 久久亚洲一区二区三区四区| 欧美大片一区二区三区| 亚洲国产视频直播| 欧美顶级艳妇交换群宴| 亚洲欧洲综合另类| 一区二区三区四区国产| 欧美午夜三级| 亚洲免费小视频| 久久女同精品一区二区| 伊人一区二区三区久久精品| 美女黄毛**国产精品啪啪| 亚洲国产成人av| 99在线精品视频在线观看| 欧美日韩综合精品| 亚洲欧美日韩综合| 麻豆91精品91久久久的内涵| 亚洲精品一二三| 欧美色综合天天久久综合精品| 亚洲一区二区在线免费观看视频 | 另类酷文…触手系列精品集v1小说| 好看的亚洲午夜视频在线| 麻豆91精品| 中国成人在线视频| 久久久久久高潮国产精品视| 亚洲激情校园春色| 欧美日韩免费观看一区二区三区| 亚洲欧美三级在线| 欧美成人免费视频| 亚洲综合第一页| 在线观看成人小视频| 欧美日韩久久不卡| 久久国产免费| 日韩午夜在线观看视频| 久久在线观看视频| 夜夜夜精品看看| 国产专区精品视频| 欧美肉体xxxx裸体137大胆| 久久99伊人| 一区二区成人精品| 欧美韩日高清| 欧美一区二区三区男人的天堂| 亚洲国产精品精华液网站| 噜噜噜在线观看免费视频日韩| 一本久久a久久精品亚洲| 欧美bbbxxxxx| 国产精品日韩欧美| 免费观看不卡av| 亚洲性感激情| 亚洲福利av| 性做久久久久久| 亚洲美女视频网| 国产日韩欧美精品综合| 欧美1级日本1级| 欧美一区二视频| 亚洲精品免费观看| 久久精品国产亚洲一区二区| 在线精品视频免费观看| 欧美日韩精品一区二区三区| 欧美亚洲系列| 亚洲国产精品久久久久秋霞影院 | 欧美一区视频| 亚洲国产成人在线视频| 欧美性做爰毛片| 久久久久久久性| 在线一区免费观看| 欧美国产免费| 久久久久久网站| 亚洲伊人色欲综合网| 一区二区三区在线免费观看| 欧美性大战久久久久久久蜜臀| 欧美淫片网站| 亚洲一区三区在线观看| 亚洲精品欧美日韩专区| 亚洲区免费影片| 欧美成年人视频网站| 欧美一区二区视频免费观看 | 在线观看欧美成人| 国产精品视频久久久| 欧美日韩第一区| 欧美精品乱码久久久久久按摩| 亚洲欧美精品伊人久久| 亚洲国产精品日韩| 亚洲精品极品| aa级大片欧美| 亚洲网站视频福利| 亚洲小说欧美另类婷婷| 亚洲在线中文字幕| 亚洲欧美韩国| 久久不射2019中文字幕| 久久久久一区| 欧美不卡三区| 欧美日韩亚洲一区二区三区四区| 欧美日韩一区视频| 国产精品亚洲片夜色在线| 国产精品久久久一本精品| 欧美天堂亚洲电影院在线观看| 国产精品黄色| 国产亚洲高清视频| 尹人成人综合网| 99精品欧美一区二区三区综合在线 | 亚洲精品字幕| 亚洲视频免费在线| 欧美中日韩免费视频| 久久久噜噜噜久久中文字免| 欧美成年网站| 欧美日韩日日夜夜| 国产精品中文在线| 影音先锋在线一区| 宅男噜噜噜66一区二区66| 亚洲欧美日韩天堂| 免费成人美女女| 亚洲美女视频网| 欧美有码在线视频| 欧美国产日韩亚洲一区| 国产精品久久福利| 亚洲国产精品久久久久| 亚洲一区二区三区精品视频| 久久久久网址| 亚洲伦理自拍| 久久精品中文字幕一区二区三区| 欧美激情一区二区三区在线| 国产精品综合不卡av| 亚洲国产va精品久久久不卡综合| 亚洲一区二区在线免费观看| 蘑菇福利视频一区播放| 亚洲图片你懂的| 欧美插天视频在线播放| 国产伦精品一区二区三区照片91 | 亚洲免费一在线| 欧美二区视频| 国内外成人免费激情在线视频| 亚洲精选视频免费看| 午夜亚洲伦理| 亚洲伦理在线免费看| 久久亚洲色图| 国产亚洲制服色| 亚洲一级在线| 亚洲国产人成综合网站| 久久国产福利| 国产精品理论片| 亚洲精品欧美日韩专区| 欧美一区二区三区在| 一本色道久久综合狠狠躁的推荐| 久久综合五月| 精东粉嫩av免费一区二区三区| 亚洲欧美日韩爽爽影院| 亚洲毛片在线观看.| 午夜久久影院| 国产欧美精品xxxx另类| 亚洲欧美成人| 亚洲美女av网站| 欧美精品一区二区在线观看| 亚洲国产精品久久人人爱蜜臀| 久久久国产精彩视频美女艺术照福利 | 91久久精品国产| 免费中文日韩| 亚洲黄一区二区| 欧美激情视频在线免费观看 欧美视频免费一 | 国产一区二区在线观看免费播放| 亚洲欧美激情一区| 这里只有视频精品| 欧美调教vk| 亚洲综合不卡| 亚洲一级二级| 国产精品影视天天线| 欧美一二三区精品| 亚洲欧美中文日韩在线| 国产欧美综合一区二区三区| 欧美在线亚洲综合一区| 亚洲免费中文|