質問

I am trying to implement an explicit conversion constructor for an assignment and I am confused what is it I am required to do. I have a WordList containing a single element, and am to make this constructor explicit so I cannot do:

WordList myList;
list = 'i'; // error
役に立ちましたか?

解決

All that you need to use explicit keyword as:

class WordList 
{
   explicit WordList(char c) {}
};

WordList w = 'i';  //error
WordList v ('i') ; //ok
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top