From this post, I see that you cannot overload operators for pointers: C ++: operator overloading <for pointers to objects
But is there a way to overload operators for force pointers? For instance:
boost::shared_ptr<ClassB> operator||(boost::shared_ptr<ClassA> lhs, boost::shared_ptr<ClassA> rhs) {
boost::shared_ptr<ClassB> returnVal = CreateClassBSharedPtr(lhs, rhs);
return returnVal;
}
When I try this, I get an ambiguous overload error (it contradicted the built-in operator || (bool, bool)). Any ideas to get around this?
Edit: adding more details on why I would like to do this.
I will try to explain that I am trying my best. I would like to make a validator object for maps that can check if certain properties are saved. For instance:
boost::shared_ptr<MyValidator> my_validator = IsEmpty("key name 1") && IsNotEmpty("key name 2") || HasNElements("key name 3", num)
Later, to check the map:
if(my_validator.validate(some_map)) { ... }
, , pass by value ( ), pass by const reference ( , , ).
: , : , ++?