首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

关于重载符的有关问题

2012-10-20 
关于重载符的问题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");
}

热点排行