C++/Object Oriented Methodology
Expert: vijayan - 9/23/2009
QuestionDifference Between Following Two Statements:
String Name = "Radhika";
String Name("Radhika");
AnswerAssuming that 'String' is a class which has a (non-explicit) constructor which can be invoked using a single argument of type const char*, for example:
class String
{
public:
String( const char* cstr ) ;
// ....
};
there is no difference between the two. Both are just two different syntactic constructs for initializing an object of type String and do exactly the same thing.
(To be very pedantic, the first form
String Name = "Radhika";
requires that the class String has an accessible copy constructor which is atleat implicitly or explicitly
declared, but you can ignore this esoteric nicety at this point of your learning curve.)