64,682
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class IntCell
{
public:
IntCell(int num = 0) :m_iNum(num)
{
cout << "\nInt-parameter constructor called.\n";
}
// Copy constructor
IntCell(const IntCell & rhs) :m_iNum(rhs.m_iNum)
{
cout << "\nThe copy constructor called.\n";
}
// Move constructor
IntCell(IntCell && rhs) :m_iNum(std::move(rhs.m_iNum))
{
cout << "\nThe move constructor called.\n";
}
private:
int m_iNum;
};
IntCell func1(int n)
{
IntCell temp{ n };
return temp;
}
IntCell func2(int n)
{
return IntCell(n);
}
void separation( )
{
cout << "\n------------------------------------------------------\n";
}
int main( )
{
int num = 12;
cout << "\nThe functions invoked by\nfunc1(num);\n";
func1(num);
separation( );
cout << "\nThe functions invoked by\nfunc2(num);\n";
func2(num);
separation();
}
The functions invoked by
func1(num);
Int-parameter constructor called.
The move constructor called.
------------------------------------------------------
The functions invoked by
func2(num);
Int-parameter constructor called.
------------------------------------------------------
func1(num);
func2(num);