Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create overloaded operators for boost pointers in C++?
    primarykey
    data
    text
    <p>From this post I see that you can't overload operators for pointers: <a href="https://stackoverflow.com/questions/1419997/c-operator-overloading-of-for-pointers-to-objects">C++: Operator overloading of &lt; for pointers to objects</a></p> <p>But is there any way I could overload operators for boost pointers? For example:</p> <pre><code> boost::shared_ptr&lt;ClassB&gt; operator||(boost::shared_ptr&lt;ClassA&gt; lhs, boost::shared_ptr&lt;ClassA&gt; rhs) { boost::shared_ptr&lt;ClassB&gt; returnVal = CreateClassBSharedPtr(lhs, rhs); return returnVal; } </code></pre> <p>When attempting this, I get an ambiguous overload error (it conflicted with the built in operator||(bool, bool)). Any ideas to get around this?</p> <p><strong>Edit: Adding some more details below as to why I'd like to do this.</strong></p> <p>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:</p> <pre><code>boost::shared_ptr&lt;MyValidator&gt; my_validator = IsEmpty("key name 1") &amp;&amp; IsNotEmpty("key name 2") || HasNElements("key name 3", num) </code></pre> <p>Later, to validate a map:</p> <pre><code>if(my_validator.validate(some_map)) { ... } </code></pre> <p>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). </p> <p><strong>Edit: Added a new question specific to my problem here:</strong> <a href="https://stackoverflow.com/questions/3441608/implementation-suggestions-for-creating-an-expression-later-used-to-evaluate-the">Implementation suggestions for creating an expression later used to evaluate the contents of a map in c++?</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload