关于重载符的有关问题
关于重载符的问题C/C++ code#include iostream#include windows.husing namespace stdclass a{public
关于重载符的问题
C/C++ code#include <iostream>#include <windows.h>using namespace std;class a{public: void setb(int b) { a::b = b; } int b; void print() { cout<<++b<<endl; } double operator ++(double d)//(double d) { return d + 10; }};void main(){ a T; int b; T.setb(50); cin>>b;}
E:\test\t.cpp(16) : error C2807: the second formal parameter to postfix 'operator ++' must be 'int'
E:\test\t.cpp(16) : error C2333: '++' : error in function declaration; skipping function body
出现这两个出错
[解决办法]#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
class a
{
public:
void setb(int b1) { a::b = b1; }
int b;
void print() { cout<<++b<<endl; }
int operator ++(int d)//(double d)
{
return d + 10;
}
};
void main()
{
a T;
int b;
T.setb(50);
T.print();
cin>>b;
T.print();
system("pause");
}