我有一个赋值,用but构造操作符重载,我尝试构造operator<<以向左移动整数,但是当我声明函数时是:friend const int operator<<(const int&,int& );编者注意到错误所以我不让操作员超载operator<<。这是我的密码:
#pragma once//bitwise.h
#include<iostream>
using namespace std;
class bitwise
{ private:
int n;
public:
bitwise(int n){
this->n = n;
}
friend const int operator<<(const int& , int& );//complier notice error here.
};
const int operator<<(const int& n, int& x){
int temp=n*pow(2, x);
return temp;
}发布于 2016-04-10 14:40:09
在创建操作符的过程中,它试图重新定义使用shift(左移)和两个整数,而不是类的含义。你想要这样的东西:
friend int operator<<(const bitwise& , int);https://stackoverflow.com/questions/36531069
复制相似问题