[
https://issues.apache.org/jira/browse/MESOS-1057?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13924135#comment-13924135
]
Bernd Mathiske commented on MESOS-1057:
---------------------------------------
I believe it is relatively easy to tell whether implicit conversion is wanted
or not. Sometimes it is the case when the parameter type is a POD or when it is
a synonym for the constructed type from another realm. The compiler will tell
me when an implicit conversion was in use after I patched in "explicit" and
then I can assess the situation(s) at the call site(s). Here are some examples
from libproc where implicit conversions can be safely excluded as it seems:
ProcessReference(ProcessBase* _process)
HttpProxy(const Socket& _socket)
ProcessManager(const string& delegate)
FilterVisitor(bool* _filter)
JSONVisitor(JSON::Array* _events)
Slave(const PID &_master)
DelegatorProcess(const UPID& delegatee)
FileServer(const string& _path)
> libprocess: Add explicit to single argument constructors
> --------------------------------------------------------
>
> Key: MESOS-1057
> URL: https://issues.apache.org/jira/browse/MESOS-1057
> Project: Mesos
> Issue Type: Improvement
> Components: libprocess
> Reporter: Bernd Mathiske
> Assignee: Bernd Mathiske
> Priority: Minor
> Labels: newbie, style
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> Exactly like MESOS-1055, just splitting out the task for lib process into a
> separate issue.
> From the google style guide:
> Normally, if a constructor takes one argument, it can be used as a
> conversion. For instance, if you define Foo::Foo(string name) and then pass a
> string to a function that expects a Foo, the constructor will be called to
> convert the string into a Foo and will pass the Foo to your function for you.
> This can be convenient but is also a source of trouble when things get
> converted and new objects created without you meaning them to. Declaring a
> constructor explicit prevents it from being invoked implicitly as a
> conversion.
> Implicit conversions should be the exception to avoid unwanted and unexpected
> behaviour.
--
This message was sent by Atlassian JIRA
(v6.2#6252)