0

For an assignment I need to create a class that can do arbitrary precision arithmetic. This is the simplest definition of the class:

class MyClass() {
private:
    std::vector<unsigned char> digits
public:
    MyClass(); // Default constructor
    MyClass(const MyClass& other); // Copy Constructor
    MyClass(MyClass&& other); // Move Constructor

    MyClass(std::vector<unsigned char> digits);
    MyClass(unsigned long long value);

// Arithmetic and comparison operators defined below...

I was attempting to implement the multiplication operator, which has the signature MyClass operator*(const MyClass& other), when I found that this code causes a compiler error:

MyClass rv();
MyClass a(10);
rv = rv + a;
return rv;

Line 3 errors with Expression must be a modifiable lvalue

Line 4 errors with No suitable constructor exists to convert from "MyClass ()" to "MyClass"

However, if I change the first line to either MyClass rv; or MyClass rv = MyClass();, the error goes away. Why is this?

I'm using the MSVC compiler on Windows 10.

0 Answers0