Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to overload output stream in C++
    primarykey
    data
    text
    <p>I am trying to overload the &lt;&lt; operator in my class <code>STEntry</code> but keep running into this error. My class is pasted bellow the error.</p> <pre><code>stentry.h: In function ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const STEntry&amp;)’: stentry.h:48: error: no match for ‘operator&lt;&lt;’ in ‘std::operator&lt;&lt; [with _CharT = char, _Traits = std::char_traits&lt;char&gt;, _Alloc = std::allocator&lt;char&gt;](((std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)((std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;*)out)), ((const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;)(&amp; temp-&gt;STEntry::lexeme))) &lt;&lt; ','’ stentry.h:46: note: candidates are: std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const STEntry&amp;) </code></pre> <p>My class in STEntry.h. It is pretty simple. Im trying to display some variable values.</p> <pre><code>#ifndef __STENTRY__ #define __STENTRY__ #include &lt;string&gt; using namespace std; class STEntry { public: string lexeme; // addr. of lexema associated with this entry int tokenval; // token value for this entry int offset; // location of variable in block STEntry(string name = "", int newval = 0, int newoffset = 0); // function: constructor ... initializes major fields // Relational operators: bool operator == (const STEntry &amp;) const; bool operator != (const STEntry &amp;) const; friend ostream &amp; operator &lt;&lt; (ostream &amp;, const STEntry &amp;); }; //--- BEGIN IMPLEMENTATION //constructor STEntry::STEntry(string name, int newval, int newoffset) { lexeme = name; tokenval = newval; offset = newoffset; } // .... //Output a single STEntry to standard output std::ostream&amp; operator &lt;&lt; (std::ostream&amp; out, const STEntry &amp; temp) { out &lt;&lt; temp.lexeme &lt;&lt; ',' &lt;&lt; temp.tokenval &lt;&lt; ',' &lt;&lt; temp.offset; return out; } //--- END OF IMPLEMENTATION #endif </code></pre>
    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.
    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