0

I have a assignment that construct Operator overloading with bitwise.I try to construct operator<< to shift integer left,but when I declare function is: friend const int operator<<(const int& , int& ); the complier notice error nomember operator requier a parameter with class or enum type.. So I don't operator overloading with operator<<. This is my code:

#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;
}

1 Answers1

0

The way you are creating the operator, it is trying to redefine what it means to use shift-left with two integers, and not with your class. You want something like this:

friend int operator<<(const bitwise& , int);
Vaughn Cato
  • 63,448
  • 5
  • 82
  • 132