0

I am getting the following error:

main.cpp:18:49: error: ‘intervall operator+(inv*, inv*)’ must have an argument of class or enumerated type
 inline struct intervall operator+(inv* a, inv* b){

It happens when I attempt to execute the following code:

typedef struct intervall inv;


//Intervallstruct
struct intervall
{
  double sup;
  double inf;
} x;



//Addition
inline struct intervall operator+(inv* a, inv* b){
    inv c;
    
    c.inf=a->inf+b->inf;
    c.sup=a->sup+b->sup;
    return c;
}

//Input
istream& operator>>(istream& is, struct intervall* x){
is >> x->inf >> x->sup;    
return is;
}

I do not understand why I cannot use the argument inv* to overload operator+ like this, since the other function works just fine.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    You should not be overloading operators using pointers at all. Operators act on actual object instances instead, which should be passed in by reference, eg: `inv operator+(const inv &a, const inv &b)` and `istream& operator>>(istream& is, const inv &x)`, respectively. – Remy Lebeau Jun 24 '20 at 01:55
  • `istream& operator>>(istream& is, struct intervall* x)` is not recommended as it will not be found by ADL. You should follow the advice in the error message, read into `struct intervall&` instead of a pointer to it, same with `inv` – M.M Jun 24 '20 at 01:57

0 Answers0