<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/2030/1/7/_/styles/combined.css?spaceKey=TOP&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/TOP/Style+Guide?focusedCommentId=9568786#comment-9568786">Style Guide</a></h2>
    <h4>Comment edited by             <a href="https://wiki.asterisk.org/wiki/display/~dlee">David M. Lee</a>
     :</h4>
    <br/>
                        <h4>Changes (1)</h4>
                                
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{ <br>    Foo allowed(&quot;allowed&quot;);        // no error <br></td></tr>
            <tr><td class="diff-changed-lines" >Foo <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">alsoDisallowed</span> <span class="diff-added-words"style="background-color: #dfd;">disallowed</span> = <span class="diff-changed-words">std::string(&quot;<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">also </span>disallowed&quot;);</span> // error: conversion from ‘std::string’ to non-scalar type ‘Foo’ requested <br></td></tr>
            <tr><td class="diff-unchanged" >} <br>{code} <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                          <div class="notificationGreySide">
            <blockquote><p>constructors that accept only a const std::string should not be marked explicit, otherwise a constant static string (which is of type const char *) could not be passed as an argument to the constructor.</p></blockquote>

<p>Not quite.  An explicit ctor on <tt>Foo</tt> would disallow conversion from <tt>std::string</tt> to <tt>Foo</tt>, not <tt>char*</tt> to <tt>std::string</tt>.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: cpp; gutter: false"><![CDATA[
#include &lt;iostream&gt;

class Foo
{
public:
    explicit Foo(const std::string&amp; name) {}
};

int main()
{
    Foo allowed("allowed");        // no error
    Foo disallowed = std::string("disallowed"); // error: conversion from ‘std::string’ to non-scalar type ‘Foo’ requested
}
]]></script>
</div></div>
        </div>
    
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="https://wiki.asterisk.org/wiki/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
       </div>
       <a href="https://wiki.asterisk.org/wiki/display/TOP/Style+Guide?focusedCommentId=9568786#comment-9568786">View Online</a>
              |
       <a id="reply-9568786" href="https://wiki.asterisk.org/wiki/display/TOP/Style+Guide?replyToComment=9568786#comment-9568786">Reply To This</a>
           </div>

</div>
</div>
</div>
</div>
</body>
</html>