Here I am, once more with a rather basic question, I am wondering what does this code do ?
1 2 3 4 5
class Sales_item {
public:
//What does *this represent? To what object does it point ?
Sales_item(std::istream &is) { is >> *this; }
}
The constructor in the code above will be used to initialize an Object of type Sales_item, but what I don't get is how or where does *this is made to point to a Sales_item object, because I think, and I maybe wrong, a constructor does not involve a caller yet, instead it will create the object in the first place. Am I right?
This constructor calls operator >> (std::istream&, Sales_item&)(or something like that..)
what I don't get is how or where does *this is made to point to a Sales_item object
this is the Sales_item object. It's not some variable, it's a keyword. A way to get the address of the object in its member functions. You could say that this is initialized when the object is allocated (right before calling the constructor), if you must.
a constructor does not involve a caller yet, instead it will create the object in the first place.
What do you mean by 'caller'? Anyway, I'd say the constructor 'initializes' the object, not 'creates' it. It's just a lump of memory. There is nothing to 'create'..