Bloomberg LP Interview Question
Financial Software DevelopersIt will compile... it will even run if you put the declaration:
String s = "asas"
in the main program. However, since the constructors and assignment operator are empty and there is no storage associated with the class, no data will ever be associated with the class which makes it of very questionable usefulness.
Its tricky. The constructor is declared as explicit. So declarations of the form String s ="asas"; may be illegal.
However the explicit constructor's parameter list has only a char ch and not a character array, which the non-explicit constructor has (char *p), so in this case String s ="asas" should compile.
If the 2 constructor was not declared to be explicit then the code will not compile. The reason for that is the call to the constructor will be ambiguous.
Now when the 2 constructor is declared explicit the ambiguity is removed when we declare objects of the type string s1= "abc".
Ambiguity still exists when object is created this way
string s1("abc")
google "c++ explicit" for the reason, I am unable to post link to the web page
Here i forgot the part mentioned in the main , but i think it was some thing like String s = "asas";
- TopCoder February 23, 2010