From this post I see that you can't overload operators for pointers: http://stackoverflow.com/questions/1419997/c-operator-overloading-of-for-pointers-to-objects
But is there any way I could overload operators for boost pointers? For example:
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 attempting this, I get an ambiguous overload error (it conflicted with the built in operator||(bool, bool)). Any ideas to get around this?
Edit: Adding some more details below as to why I'd like to do this.
I'll try to explain what I'm attempting as best I can. What I'd like to do is make a "validator" object for maps that can check if certain properties hold. For example:
boost::shared_ptr<MyValidator> my_validator = IsEmpty("key name 1") && IsNotEmpty("key name 2") || HasNElements("key name 3", num)
Later, to validate a map:
if(my_validator.validate(some_map)) { ... }
I think I'm stuck with using pointers because I can't use pass by value (since I'm making use of polymorphism) and I can't use pass by const reference (since there would be temporary object created by nesting operators that would not exist later when trying to validate).
Edit: Added a new question specific to my problem here: http://stackoverflow.com/questions/3441608/implementation-suggestions-for-creating-an-expression-later-used-to-evaluate-the