#include <iostream>
usingnamespace std;
class Color
{
string y;
public:
Color (string x)
{
y = x;
cout << y << "\n";
}
};
int main ()
{
string favoritecolor;
cout << "What is your favorite color?" << "\n";
getline (cin,favoritecolor);
Color ("Why can't I pass a variable to the constructor?"); //what is the difference between this?
Color favorite (favoritecolor); //and this?
//what are the limits for each of the call statements?
}
Color ("Why can't I pass a variable to the constructor?"); is a cast-expression of type Color.
(Implicit conversion from const char* to std::string, explicit conversion from std::string to Colour).
It yields a prvalue ("pure" rvalue).
Color favorite (favoritecolor); is a declaration-statement for a variable with automatic storage duration.
After this declaration, the expression favorite is an lvalue of type Colour.