could not convert this to an unreferenced type

Hello all, I have the following two classes:

class Element{

  public:

  bool _use;

  Element(int _npin);
  Element();
  Element(const Element& _val);
  Element operator=(const Element& _val);
  bool operator==(const Element& _val);
  bool operator!=(const Element& _val);
  void AndSelf();
  byte GetAnd();
  byte GetOr();
  int GetPin();
  _which_port GetPort();
  void OrSelf();
  void SetPin(int _npin);

  private:

    byte _and;
    byte _or;
    int _pin;
    _which_port _which;    
    
};

class ValsL1{

  public:
    bool _vals[7];
    
    ValsL1();
    ValsL1(const ValsL1 &_nvals);
    ValsL1 operator=(const ValsL1& _val);
    bool operator==(const ValsL1& _val);
    bool operator!=(const ValsL1& _val);
    bool* GetVals();
    bool GetVal(int _index);
    
  private:    
  
};

When I compile the code though, the element class is compiling just fine but the ValsL1 class gives the following error:
sevenseg.cpp:54:14: error: could not convert ‘(ValsL1*)this’ from ‘ValsL1*’ to ‘ValsL1’

return this;

It is the exact same declaration and definition as the Element class but the copy operator on ValsL1 wont compile. heres the definition of both:

ValsL1 ValsL1::operator=(const ValsL1& _val){

  for(int x=0;x<7;x++){

    if(_vals[x]!=_val.GetVal(x)){

      return this;
      break;
      
    }
    
  }

  ValsL1 _ret(_val);
  
  return _ret;
  
}


Element Element::operator=(const Element& _val){

  if(_pin==_val.GetPin() && _and==_val.GetAnd() && _or==_val.GetOr() && _which==_val.GetPort() && _use==_val._use){

    return this;
    
  }

  Element _ret(_val);

  return _ret;
  
}

what am I missing?

Thanks in advance.

The “this” item is a pointer. Your function that returns this is NOT defined to return a pointer.

  _which_port GetPort();

What the hell is a _which_port?

Your class(es) make no sense.

The which_port is an enumeration. Two questions though, how should the assignment operator look and why is the compiler only complaining about the ValsL1 assignment operator when the elements assignment operator is doing the exact same thing ?

how should the assignment operator look

You are returning a pointer, so the operator must be defined as returning a pointer, not an object.

    ValsL1 *operator=(const ValsL1& _val);

why is the compiler only complaining about the ValsL1 assignment operator when the elements assignment operator is doing the exact same thing ?

The code is NOT identical. The ValsL1 operator implementation has a useless break; after the return statement in the if body.

It would easier to compare the code if you:
Put each function in it's own code window.
Used the enter key once in a while, so we didn't have to scroll back and forth as well as up and down to compare the code.

Why is _vals a public field of ValsL1?

Why do member names start with _ and arguments names start with _? Typically, one uses the _ prefix (I personally do not, as I hate underscores in names) to distinguish member fields from local variables and function arguments. Using underscores in both member and argument names just leads to difficult to follow code.

Other issues aside, this appear to be gibberish:

ValsL1 ValsL1::operator=(const ValsL1& _val) {
  for (int x = 0; x < 7; x++) {
    if (_vals[x] != _val.GetVal(x)) {
      return this;
      break;
    }
  }
  ValsL1 _ret(_val);
  return _ret;
}

You’re passing the assignment operator a reference to an object and then treating it like an array. Then, you’re trying to compare each element of the (no-existent) object array to the result of a method that claims to return a pointer to a bool.

As already mentioned, the break statement is pointless.

Finally, you try to return either an ValsL1 object or a pointer to the current ValsL1 object.

You're passing the assignment operator a reference to an object and then treating it like an array.

_val (the reference) and _vals (the array) are completely separate things.

Finally, you try to return either an ValsL1 object or a pointer to the current ValsL1 object.

In one case, he/she is returning a pointer. In the other case, he/she is returning a copy of the referenced object.

Both return statements have to return the same type (_ret or *this, with the return type being ValsL1).

PaulS:
_val (the reference) and _vals (the array) are completely separate things.

You're right. But, kind of a poor choice of variable names. I still don't think comparing it to the return value of "_val.GetVal(x)" makes any sense.

In one case, he/she is returning a pointer. In the other case, he/she is returning a copy of the referenced object.
Both return statements have to return the same type (_ret or *this, with the return type being ValsL1).

That was my point.

But, kind of a poor choice of variable names.

Both classes are littered with names that mean nothing.