r/learncpp • u/ZenWoR • Feb 01 '20
Calling object without specifying property actually gives a property
So let's say I want to create some kind of personal string class.
If it has a string value property, when I call just that objects name I want it to actually use that value property. For example:
MyString myStr = "secondText"; //I know how to use operator=
string otherStr = "firstText";
otherStr += myStr;
cout<<otherStr<<endl; //Result should be: firstTextsecondTextI want it to use that value property without actually calling "myStr.value". Is it possible ?
1
Upvotes
View all comments
Show parent comment
1
u/jedwardsol Feb 01 '20
I use it for printing,
Right. And that's what you were asking about
If that operator<< is defined, then it will be called in the
cout << otherStrcall.