Question

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
Was it helpful?

Solution

All that you need to use explicit keyword as:

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

WordList w = 'i';  //error
WordList v ('i') ; //ok
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top