0

in VS2017 i get error C2660. There are many posts related to this, but i found no case comparable with mine.

Situation: Class A implements getter/setter for _mem. The setter is virtual and overwritten in B. In B function "set" i call the getter, which is only declared in A and is void. So a pretty unique thing. Why even though getting c2660? I dont see it, sorry for that.

(Want only setter - which expects a param value - overwrite and keeping getter which does not take any parameters.)

class A
{
public:
    A(int x)
    {
        _mem=x;
    }
    inline int mem(void) const {return _mem;}
    virtual  bool mem (int x) {  _mem=x; return true;}
protected:
    int _mem;
};

class B : public A
{
public:
    B (int x)   : A(x)
    {
    }
public:
    bool mem (int x) { _mem = x;return true; }

    void    set(const B& x)
    {
        x.mem(); // c2660
    }
};
nullptr
  • 93
  • 11
  • 1
    Declaring `mem(int)` in `B` hides *all* `mem` overloads from `A`, and so the only candidate for `x.mem()` is `B::mem(int)`, which obviously has a different number of arguments. Hence the C2660 error. See the linked duplicate question. The fix is adding `using A::mem;` inside of `B`'s definition. – cdhowie Sep 15 '17 at 17:13
  • Which `mem` are you expectiong to be called here: `x.mem();` ? And why? –  Sep 15 '17 at 17:13
  • Thank you for answer: Expect A::mem(void) to be called, because it has no parameters and the setter >expects< a param. So it is unique what to be called. – nullptr Sep 15 '17 at 17:50

0 Answers0