c++ explicit keyword for function without arguments -


possible duplicate:
what explicit keyword in c++ mean?

is there reason use explicit keyword function doesn't take arguments? have effect? i'm wondering because came across line

explicit char_separator()

near end of page documenting boost::char_separator ( http://www.boost.org/doc/libs/1_47_0/libs/tokenizer/char_separator.htm ), it's not explained further there.

reading explanation of members :

explicit char_separator(const char* dropped_delims,                         const char* kept_delims = "",                         empty_token_policy empty_tokens = drop_empty_tokens) explicit char_separator() 

the explicit keyword 1st constructor requires explicit creation of objects of char_separator type. what explicit keyword mean in c++? covers explicit keyword well.

the explicit keyword 2nd constructor noise , ignored.

edit

from c++ standard :

7.1.2 p6 tells :

the explicit specifier shall used in declarations of constructors within class declaration; see 12.3.1.

12.3.1 p2 tells :

an explicit constructor constructs objects non-explicit constructors, direct-initialization syntax (8.5) or casts (5.2.9, 5.4) explicitly used. default constructor may explicit constructor; such constructor used perform default-initialization or value-initialization (8.5). [example:

class z { public: explicit z(); explicit z(int); // ... }; z a;               // ok: default-initialization performed z a1 = 1;          // error: no implicit conversion z a3 = z(1);       // ok: direct initialization syntax used z a2(1);           // ok: direct initialization syntax used z* p = new z(1);   // ok: direct initialization syntax used z a4 = (z)1;       // ok: explicit cast used z a5 = static_cast<z>(1); // ok: explicit cast used 

—end example]

so, default constructor explicit keyword same without keyword.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -