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

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

  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 沛沛 閱讀(283) 評論(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>
            亚洲免费在线观看| 香蕉久久一区二区不卡无毒影院 | 久久综合网hezyo| 久久久999精品视频| 久久婷婷丁香| 亚洲电影第三页| 亚洲精品久久久久久下一站| 最新日韩中文字幕| 亚洲图片在线| 久久免费的精品国产v∧| 欧美 亚欧 日韩视频在线| 欧美欧美在线| 国产日韩精品一区二区| 在线播放中文一区| 亚洲视频精品在线| 久久午夜av| 亚洲最快最全在线视频| 欧美在线一级va免费观看| 欧美护士18xxxxhd| 国产欧美日韩在线| 日韩视频在线永久播放| 性色av一区二区三区红粉影视| 久久久免费av| 亚洲午夜极品| 久热精品视频在线观看| 国产精品久久久久一区二区三区| 国模精品娜娜一二三区| 一区二区三区鲁丝不卡| 免费黄网站欧美| 午夜精品视频在线观看| 欧美日本韩国在线| 在线观看成人一级片| 亚洲欧美日韩视频一区| 亚洲国产婷婷综合在线精品| 欧美在线不卡| 国产噜噜噜噜噜久久久久久久久 | 久久一区亚洲| 国产精品夜夜夜| 一区二区三区欧美视频| 欧美韩国一区| 久久久久这里只有精品| 国产日韩在线视频| 亚洲欧美国产精品桃花| 亚洲欧洲一区| 美日韩精品免费观看视频| 国产亚洲精品成人av久久ww| 亚洲一区二区欧美| 亚洲精品一区中文| 欧美大胆人体视频| 亚洲国产综合视频在线观看| 女同性一区二区三区人了人一| 欧美一区二区三区另类| 国产精品免费视频xxxx| 亚洲一区在线观看免费观看电影高清 | 欧美区一区二| 亚洲精品久久久久久久久久久 | 亚洲午夜在线观看视频在线| 欧美欧美全黄| 亚洲在线播放| 亚洲一区二区在线免费观看| 国产精品乱人伦中文| 午夜激情久久久| 亚洲欧美综合另类中字| 国产在线不卡精品| 免费在线欧美视频| 欧美成ee人免费视频| 一区二区精品| 一区二区电影免费在线观看| 国产精品99免费看 | 欧美成人午夜激情在线| 亚洲美女视频在线观看| 欧美体内she精视频| 亚洲国产日日夜夜| 亚洲福利视频二区| 欧美日韩免费一区二区三区| 日韩网站在线看片你懂的| 久久久综合精品| 久久综合久久综合久久综合| 亚洲九九爱视频| 日韩亚洲欧美精品| 国产精品外国| 欧美高清视频一区| 欧美日韩一区二区在线| 欧美一区二区三区另类 | 老妇喷水一区二区三区| 母乳一区在线观看| 亚洲欧美成人一区二区三区| 欧美一级视频免费在线观看| 亚洲国产一二三| 在线视频免费在线观看一区二区| 国产日本欧美视频| 亚洲国产毛片完整版| 国产精品日本欧美一区二区三区| 久久亚洲风情| 国产精品福利久久久| 免费亚洲电影| 国产精品欧美激情| 亚洲国产aⅴ天堂久久| 国产精品一区二区三区成人| 欧美国产激情| 国产视频在线一区二区| 亚洲乱码国产乱码精品精天堂 | 亚洲福利视频网| 一区二区三区国产盗摄| 悠悠资源网亚洲青| 亚洲欧美国产另类| 夜夜嗨一区二区三区| 久久精品视频免费观看| 亚洲一区二区在线观看视频| 欧美成va人片在线观看| 狂野欧美一区| 国产日韩综合| 亚洲一级二级在线| 一二三区精品| 欧美激情综合五月色丁香小说| 久久精品一二三区| 国产精品一区二区男女羞羞无遮挡 | 欧美激情久久久久久| 国产欧美在线看| 亚洲天堂第二页| 99精品国产福利在线观看免费 | 亚洲欧美日韩在线播放| 欧美在线一二三四区| 欧美xxxx在线观看| 欧美一区二视频| 欧美午夜不卡| 99精品欧美一区二区三区综合在线| 亚洲国产黄色| 久久一区视频| 亚洲电影免费在线| 亚洲国产三级网| 久久综合999| 欧美成人午夜激情视频| 激情六月综合| 免费高清在线一区| 欧美国产视频日韩| 亚洲欧洲在线播放| 欧美成人在线网站| 亚洲区一区二| 亚洲一区二区精品视频| 国产精品地址| 午夜精品在线观看| 久久裸体视频| 在线看片欧美| 欧美成人精品在线观看| 亚洲精品乱码久久久久久蜜桃麻豆| 日韩午夜激情| 国产精品白丝黑袜喷水久久久| 亚洲图片欧洲图片日韩av| 久久精品国产99精品国产亚洲性色| 国产日韩综合| 欧美成人精品激情在线观看 | 欧美一区二区视频网站| 国产欧美日韩一区二区三区| 久久精品日韩欧美| 91久久精品国产91性色tv| 亚洲一区成人| 黄色资源网久久资源365| 欧美福利影院| 亚洲综合电影一区二区三区| 男人的天堂成人在线| 亚洲精品亚洲人成人网| 欧美吻胸吃奶大尺度电影| 欧美一区二区三区免费观看视频 | 欧美在线免费观看视频| 欧美激情无毛| 欧美一区二区福利在线| 亚洲国产成人不卡| 国产精品久久久久aaaa九色| 卡一卡二国产精品| 亚洲视频在线免费观看| 欧美超级免费视 在线| 亚洲一区二区三区免费在线观看| 国产一区二区电影在线观看| 欧美精品久久99久久在免费线| 亚洲图片你懂的| 亚洲三级毛片| 久久久噜噜噜久久久| 一本色道久久综合亚洲精品婷婷 | 亚洲影院在线| 亚洲高清av| 国产精品一区二区a| 欧美女激情福利| 久久久综合网站| 亚洲一区欧美一区| 亚洲激情婷婷| 美日韩免费视频| 免费日韩av片| 亚洲在线一区二区三区| 欧美激情一区二区久久久| 久久不射2019中文字幕| 亚洲免费av观看| 在线欧美电影| 国产欧美亚洲日本| 欧美性猛交xxxx免费看久久久| 欧美成年人视频网站| 久久综合999| 久久青草福利网站| 久久国内精品视频| 午夜国产精品影院在线观看 |