I have it prototyped in the class, much like I would have any other function member that is later defined on the cpp file.
But there is no operator<< that takes three arguments. operator<< is dyadic.
The text in main is called with a simple std::cout << obj; (where obj is an object of Opers type). And it gave me the correct output.
Amazing.
Let's try a test:
1. oper.h
Code:
#ifndef OPER_H
#define OPER_H
#include <iosfwd>
class Opers {
public:
std::ostream& operator<<(std::ostream&, const Opers&);
int val() const { return 0; }
int text() const { return 0; }
};
#endif
2. oper.cpp
Code:
#include "oper.h"
#include <ostream>
std::ostream& operator<<(std::ostream& os, const Opers& obj) {
os << obj.val() << " - " << obj.text();
return os;
}
3. main.cpp
Code:
#include <iostream>
#include "oper.h"
int main() {
Opers test;
std::cout << test << std::endl;
}
What do you get?