I'm trying to write a <<
operator. My code:
#include <iostream>
#include <ostream>
class sound_ctl {
private:
int _vol;
bool _status;
public:
sound_ctl() : _vol(50), _status(false) {};
void operator++() {
if (_vol <= 98) {
_vol += 2;
}
}
void operator--() {
if (_vol >= 2) {
_vol -= 2;
}
}
void operator!() {
_status = !_status;
}
std::ostream &operator<<(std::ostream &os) const {
os << _status << "Volume: " + _vol << std::endl;
return os;
}
};
int main() {
sound_ctl panel1;
std::cout << panel1;
}
But, the code wont compile with error: Invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'sound_ctl')
I have a severe lack of understanding of streams in c++, so, understanding the underlying issue would help me greatly. Thanks