It might be a very silly doubt, but please bear with me.
Now let us consider the following code.
class Fred {
public:
static FredPtr create();
static FredPtr create(int i, int j);
...
private:
Fred();
Fred(int i, int j);
...
};
class FredPtr { /* ... */ };//the code above.
inline FredPtr Fred::create() { return new Fred(); }//Isn't the return type wrong ?
inline FredPtr Fred::create(int i, int j) { return new Fred(i,j); }
class Fred {
public:
static FredPtr create();
static FredPtr create(int i, int j);
...
private:
Fred();
Fred(int i, int j);
...
};
class FredPtr { /* ... */ };//the code above.
inline FredPtr Fred::create() { return new Fred(); }//Isn't the return type wrong ?
inline FredPtr Fred::create(int i, int j) { return new Fred(i,j); }
To copy to clipboard, switch view to plain text mode
and the code here
FredPtr ptr1(Fred::create());
FredPtr ptr2 = ptr1;//What will happen here ?
FredPtr ptr1(Fred::create());
FredPtr ptr2 = ptr1;//What will happen here ?
To copy to clipboard, switch view to plain text mode
Can you please explain how count will change in this case ?
Another doubt
Fred* const old = p_; means old is a const pointer to a const Fred. Then how can it be changed in the statement "if (--old->count_ == 0)" ?
Thanks a lot.
Bookmarks