<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/2030/1/7/_/styles/combined.css?spaceKey=TOP&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>Page
<b>comment added</b> by <a href="https://wiki.asterisk.org/wiki/display/~dlee">David M. Lee</a>
</h4>
<br/>
<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 <iostream>
class Foo
{
public:
explicit Foo(const std::string& name) {}
};
int main()
{
Foo allowed("allowed"); // no error
Foo alsoDisallowed = std::string("also 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>