Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    You can also do MyObject obj = bytes;. I'd suggest using the explicit keyword on the constructor to prevent that, it can avoid some surprising bugs. Commented Mar 25, 2011 at 17:50
  • If you go this way, don't forget the rule of three (en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29). You should add a destructor and copy assignment operator in there as well. Commented Mar 25, 2011 at 17:55
  • Yeah, explicit is a very good idea for single-parameter constructors. I've updated my answer. Commented Mar 25, 2011 at 18:04
  • Note that the constructor of std::string is not explicit and does what we expect. Commented Mar 25, 2011 at 22:32