Posted by on September 18, 2018, modified on December 14, 2018
範例程式:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
class Int {
public:
// for devlare
Int(const int _d){ data=_d; }
// for value to give
Int& operator = (const int _d){
data=_d;
return *this;
}
void info(void){
cout << data << "\n";
}
int val(void){
return data;
}
private:
int data;
};
ostream& operator<<(ostream& os_, Int& d_)
{
return os_ << d_.val();
}
int main(int argc, char *argv[]){
Int i=5;
i.info();
i=6;
i.info();
cout << i.val() << "\n";
return 0;
}