Hi,
I am trying to get an overloaded operator to work inside the class it
works on. The situation is something like this:
main.cc:
#include "object.hh"
#include "somefile.h h"
object obj, obj2 ;
obj2 = obj.bla(25) ;
object.hh:
class object {
public:
object() {} ;
void set_a(double num) {
a = num ;
}
double get_a( void ) {
return a;
}
bla(double num) {
return (*this) + num
}
private:
double a;
} ;
somefile.hh:
#include "object.hh"
object operator+ (double, object)
somefile.cc:
object operator+ (double a, object obj) {
obj.set_a(obj.g et_a + a) ;
}
When I compile, I find out that the object does not know that the
operator exists. Is there a way to make this work correctly?
I am trying to get an overloaded operator to work inside the class it
works on. The situation is something like this:
main.cc:
#include "object.hh"
#include "somefile.h h"
object obj, obj2 ;
obj2 = obj.bla(25) ;
object.hh:
class object {
public:
object() {} ;
void set_a(double num) {
a = num ;
}
double get_a( void ) {
return a;
}
bla(double num) {
return (*this) + num
}
private:
double a;
} ;
somefile.hh:
#include "object.hh"
object operator+ (double, object)
somefile.cc:
object operator+ (double a, object obj) {
obj.set_a(obj.g et_a + a) ;
}
When I compile, I find out that the object does not know that the
operator exists. Is there a way to make this work correctly?
Comment