c++運算符重載

這個運算符重載以爲有點像java的裝箱java

#ifndef INTERGER_H學習

#define INTERGER_Hthis

//學習下運算符的重載spa

class Interger {code

public:

    Interger();
    Interger(int value):m_value(value){}
    Interger operator+(Interger other);
    int valueOf(){
    return m_value;}

    virtual ~Interger();

protected:

private:
    int m_value;

};class

#endif // INTERGER_Htest

#include "Interger.h"di

using namespace std;vi

Interger::Interger():m_value(0)co

{ //ctor }

Interger Interger::operator+(Interger other){

Interger result=(this->m_value+other.m_value);

return result; }

Interger::~Interger() { //dtor }

int main() { Interger test1(12),test2(12),test3;

test3=test1+test2;

cout<<test3.valueOf()<<endl;

return 0;

}

相關文章
相關標籤/搜索