Note that there are some explanatory texts on larger screens.

plurals
  1. POError with derived class using overloaded operator from base class
    primarykey
    data
    text
    <p>I'll post my issue and then I'll have the code at the bottom.</p> <p>I have a base class (strSet) that has overloaded +,-,*,= operators.<br> I have a derived class (extStrSet) that has overloaded &lt;,>,== operators</p> <p>In the implementation of the overloaded '&lt;' and '>' operators in the derived class, i have to use the '*' operator (from the base class).</p> <p><strong>But I am getting an error that I'm really not sure why is happening. The errors say this:</strong></p> <pre><code>extstrset3.cpp: In member function âextStrSet extStrSet::operator&gt;(const extStrSet&amp;)â: extstrset3.cpp:17: error: no match for âoperator=â in âtemp = strSet::operator*(const strSet&amp;)(((const strSet&amp;)(&amp;((const extStrSet*)rtSide)-&gt;extStrSet::&lt;anonymous&gt;)))â extstrset3.h:11: note: candidates are: extStrSet&amp; extStrSet::operator=(const extStrSet&amp;) extstrset3.cpp: In member function âextStrSet extStrSet::operator&lt;(const extStrSet&amp;)â: extstrset3.cpp:29: error: no match for âoperator=â in âtemp = strSet::operator*(const strSet&amp;)(((const strSet&amp;)(&amp;((const extStrSet*)rtSide)-&gt;extStrSet::&lt;anonymous&gt;)))â extstrset3.h:11: note: candidates are: extStrSet&amp; extStrSet::operator=(const extStrSet&amp;) extstrset3.cpp:35: error: ânewSetâ was not declared in this scope extstrset3.cpp: In member function âextStrSet extStrSet::operator==(const extStrSet&amp;)â: extstrset3.cpp:41: error: no match for âoperator=â in âtemp = strSet::operator*(const strSet&amp;)(((const strSet&amp;)(&amp;((const extStrSet*)rtSide)-&gt;extStrSet::&lt;anonymous&gt;)))â extstrset3.h:11: note: candidates are: extStrSet&amp; extStrSet::operator=(const extStrSet&amp;) extstrset3.cpp:45: error: ânewSetâ was not declared in this scope </code></pre> <p><strong>NOTE:</strong> I am not to change either of the two header files.<br> <strong>NOTE:</strong> I know for a fact that strSet.h and strSet.cpp are implemented correctly.<br> <strong>NOTE:</strong> The overloaded '==' operator returns a extStrSet (string set) with "true" or "false" as its only string </p> <p>I should be able to use the * operator on extStrSet even though its overloaded for strSet, shouldn't I? I'm just starting inheritance so I'm still a bit wary of it.</p> <p><strong>strSet.h</strong></p> <pre><code>#ifndef STRSET_H #define STRSET_H #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; struct node { std::string s1; node * next; }; class strSet { protected: node * first; // This is initially empty (when constructed) bool isSorted () const; public: strSet (); // Create empty set strSet (std::string s); // Create singleton set strSet (const strSet &amp;copy); // Copy constructor ~strSet (); // Destructor void nullify (); // Make a set be empty bool isNull () const; int SIZE() const; void output() const; bool isMember (std::string s) const; strSet operator + (const strSet&amp; rtSide); // Union strSet operator * (const strSet&amp; rtSide); // Intersection strSet operator - (const strSet&amp; rtSide); // Set subtraction strSet&amp; operator = (const strSet&amp; rtSide); // Assignment }; // End of strSet class #endif </code></pre> <p><strong>extStrSet.h</strong></p> <pre><code>#ifndef EXTSTRSET_H #define EXTSTRSET_H #include &lt;string&gt; #include "strset3.h" class extStrSet : public strSet { public: extStrSet operator == (const extStrSet&amp; rtSide); // Equal extStrSet operator &lt; (const extStrSet&amp; rtSide); // Strict subset extStrSet operator &gt; (const extStrSet&amp; rtSide); // Strict superset // Leave off other comparisons: != &lt;= &gt;= extStrSet ( ); extStrSet (std::string s); }; inline extStrSet&amp; ss2extss (const strSet&amp; ss) // Downcast { return *(extStrSet*)&amp;ss ; } #endif </code></pre> <p><strong>extStrSet.cpp</strong></p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; #include "extstrset3.h" #include "strset3.h" using namespace std; extStrSet::extStrSet() : strSet() {} extStrSet::extStrSet(string s) : strSet(s) {} extStrSet extStrSet::operator &gt; (const extStrSet&amp; rtSide) { extStrSet temp; extStrSet temp2; extStrSet newSet; temp = *this * rtSide; temp2 = *this == rtSide; if(temp2.isMember("true")) extStrSet newSet("false"); else if( rtSide.SIZE() == temp.SIZE() ) extStrSet newSet("true"); else extStrSet newSet("false"); return newSet; } extStrSet extStrSet::operator &lt; (const extStrSet&amp; rtSide) { extStrSet temp; extStrSet temp2; temp = *this * rtSide; temp2 = *this == rtSide; if(temp2.isMember("true")) extStrSet newSet("false"); else if( SIZE() == temp.SIZE() ) extStrSet newSet("true"); else extStrSet newSet("false"); return newSet; } extStrSet extStrSet::operator == (const extStrSet&amp; rtSide) { extStrSet temp; temp = *this * rtSide; if( SIZE() == rtSide.SIZE() &amp;&amp; SIZE() == temp.SIZE() ) extStrSet newSet("true"); else extStrSet newSet("false"); return newSet; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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