copy constructor
class Cents
{
private:
int m_nCents;
public:
Cents(int nCents=0)
{
m_nCents = nCents;
}
// Copy constructor
Cents(const Cents &cSource)
{
m_nCents = cSource.m_nCents;
}
};
In above c++ code why parameter cSource(const Cents &cSource) is passed as reference?
{
private:
int m_nCents;
public:
Cents(int nCents=0)
{
m_nCents = nCents;
}
// Copy constructor
Cents(const Cents &cSource)
{
m_nCents = cSource.m_nCents;
}
};
In above c++ code why parameter cSource(const Cents &cSource) is passed as reference?
if we pass this argument as pass by value then copy constructor will call every time during copy argument. that cause struck in infinite loop. so stack overflow.
ReplyDelete@sandeep yeah correct explanation..:)
ReplyDelete