测试代码:
#pragma once
#include<iostream>
class TempConstruct
{
int nVar[10];
public:
TempConstruct()
{
std::cout <<"调用默认构造函数" << std::endl;
memset(nVar, 0, 4 * 10);
}
TempConstruct(const std::string& strTip)
{
std::cout << strTip<<"调用构造函数" << std::endl;
memset(nVar,0,4*10);
}
//拷贝构造函数
TempConstruct(const TempConstruct& other)
{
std::cout << "调用拷贝构造" << std::endl;
memcpy(this->nVar, other.nVar, 4 * 10);
}
//=函数
TempConstruct& operator=(const TempConstruct& other)
{
std::cout << "调用赋值函数" << std::endl;
memcpy(this->nVar, other.nVar, 4 * 10);
return *this;
}
void SetValue(int _nVal)
{
for (size_t i = 0; i < 10; i++)
{
nVar[i] = _nVal;
}
}
};
main.cpp
#include <QtCore/QCoreApplication&g