the code on monte_carlo.hpp is :
class Histogramme{
protected:
std::vector<double> echantillon;
unsigned int nb_boxes;
double lbound;
double ubound;
double box_width;
public:
Histogramme(double min_intervalle, double max_intervalle, unsigned int n) : nb_boxes(n), lbound(min_intervalle),
ubound(max_intervalle), box_width((max_intervalle - min_intervalle)/n),echantillon(n) {}
Histogramme& operator+=(double x);
Histogramme& operator/=(double n);
friend std::ostream& operator<<(std::ostream&, const Histogramme &);
};
And in monte_carlo.cpp :
std::ostream& operator<<(std::ostream& o,const Histogramme& H){
for(int i=0; i<H.echantillon.size(); i++){ o << H.echantillon.size() << std::endl;}
return o;
}
I don't understand why the operator << doesn't work when i remove the "const" at the Histogramme parameter, the error is :
error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream’} and ‘std::vector::size_type’ {aka ‘long unsigned int’})
const
from both definition andfriend
declaration at the same time? – Dmitry Kuzminovechantillon
. This could often result in such a misleading error message as above. – Sebastian Hoffmann