I have a class to read from/write to an external random access memory.
.h file:
class RAM {
private:
bool Read(char *Buffer, size_t BytesToRead, uint32_t StartAddress);
bool Write(char *Buffer, size_t BytesToWrite, uint32_t StartAddress);
class proxy {
private:
size_t _index;
public:
proxy(size_t i);
void operator=(char rhs);
operator char();
}
public:
proxy operator[](size_t i);
};
.cpp file:
RAM::proxy RAM::operator[](size_t i) {
return proxy(i);
}
proxy::proxy(size_t i) {
_index = i;
}
void proxy::operator=(char rhs) {
Write(&rhs, 1, _index); // error
}
RAM::proxy::operator char() {
char Buf[1];
Read(Buf, 1, _index); // error
return Buf[0];
}
Read and Write are functions that deal with low-level access to the RAM. There is no other way to read from or write to the RAM. I tried to use proxy class in rvalue - how to implement assignment operator? but couldn't adapt it without error:
error: cannot call member function 'bool RAM::Write(char*, size_t, uint32_t)' without object Write(&rhs, 1, _index)
error: cannot call member function 'bool RAM::Read(char*, size_t, uint32_t)' without object Read(Buf, 1, _index)
There are other things calling on Read and Write, so I probably can't make them static. Also I thought they are already instantiated when a RAM object is created.