retruningtemp
Counter & j = ++i; // Counter j = ++i;unknown
csharp
4 years ago
835 B
12
Indexable
// Listing 10.11 - Returning the dereferenced this pointer
#include <iostream>
using namespace std;
class Counter
{
public:
Counter();
~Counter(){}
Counter(int Val):itsVal(Val) {;}
Counter(const Counter & rhs) {itsVal=rhs.itsVal; cout<<"copy const "<<endl;}
int GetItsVal()const { return itsVal; }
void SetItsVal(int x) {itsVal = x; }
void Increment() { ++itsVal; }
Counter & operator++ ();
private:
int itsVal;
};
Counter::Counter():itsVal(0){}
Counter & Counter::operator++()
{
++itsVal;cout <<".. oper+ ... " <<endl;
return *this;
}
int main()
{
Counter i(55);
Counter & j = ++i; // Counter j = ++i;
j.SetItsVal(100);
cout << "The value of i is " <<i.GetItsVal() << endl;
cout << "The value of j is " <<j.GetItsVal() << endl;
return 0;
}
Editor is loading...