You are here:

C++/Object Oriented Methodology

Advertisement


Question
Difference Between Following Two Statements:

String Name = "Radhika";
String Name("Radhika");

Answer
Assuming 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.)

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.