Код: Выделить всё
class MyClass : public MyClassInterface {
public:
virtual ~MyClass() override;
operator const int&() const override {
return m_value;
}
private:
int m_value{};
};
Код: Выделить всё
MyClass myclass;
int val = myclass;
Код: Выделить всё
class Foo {
public:
virtual ~Foo() {}
virtual int operator[](int index) = 0;
};
class MockFoo : public Foo {
public:
MOCK_METHOD(int, BracketOp, (int index));
virtual int operator[](int index) override { return BracketOp(index); }
};
Код: Выделить всё
class Bar {
public:
virtual ~Bar() {}
virtual operator const int&() = 0;
};
class MockBar : public Bar {
public:
MOCK_METHOD(int, RefOp, ());
virtual operator const int&() override { return RefOp(); }
};
Код: Выделить всё
error: returning reference to temporary [-Werror=return-local-addr]
1173 | virtual operator const int&() override { return RefOp(); }
| ~~~~~^~
Подробнее здесь: https://stackoverflow.com/questions/782 ... -reference