C++赋值运算符重载

#pragma once
class CNumber
{
public:
CNumber(void);
CNumber(int total);
~CNumber(void);
void ShowNumber();
int GetTotal();

CNumber & operator = (const CNumber &number);

public:
int m_nTotal;
};

 

#include "Number.h"
#include <iostream>
using namespace std;

CNumber::CNumber(void)
{
}

CNumber::CNumber( int total )
{
this->m_nTotal = total;
}


CNumber::~CNumber(void)
{
}

void CNumber::ShowNumber()
{
cout << this->m_nTotal << endl;
}

CNumber & CNumber::operator = (const CNumber &number)
{
// this->m_nTotal = number.GetTotal();
cout << " start " << endl;
this->m_nTotal = number.m_nTotal;

return *this;
}

int CNumber::GetTotal()
{
return this->m_nTotal;
}

 

#include "Number.h"
#include <iostream>
#include <stdio.h>
#include "Person.h"
#include <string>
#include <boost/smart_ptr.hpp>
using namespace std;

using namespace std;

void main()
{

CNumber number1(20);
CNumber number2;
number2 = number1;
cout << number2.m_nTotal << endl;
int wait ;
cin >> wait;

return ;

}

posted @ 2013-07-01 21:04  Predator  阅读(176)  评论(0编辑  收藏  举报