Note that there are some explanatory texts on larger screens.

plurals
  1. POStuck on C++ template - deriving from std::map
    primarykey
    data
    text
    <p>I'm going to extend the existing std::map class and add a new function to it:</p> <pre><code>template&lt;typename key_type, typename value_type&gt; class CleanableMap : public Cleanable, public std::map&lt;key_type, value_type&gt; { CleanableMap(const CleanableMap&amp; in); //not implemented CleanableMap&amp; operator=(const CleanableMap&amp; in); //not implemented public: CleanableMap() {} CleanableMap(const std::map&lt;key_type, value_type&gt;&amp; in) { *this = in; } virtual ~CleanableMap() {} std::map&lt;key_type, value_type&gt;&amp; operator=(const std::map&lt;key_type, value_type&gt;&amp; in) { *((std::map&lt;key_type, value_type&gt;*)this) = in; return *this; } }; </code></pre> <p>I've got a copy constructor and assignment operator such that I can simply assign an existing std::map of the same type to my new map:</p> <pre><code>CleanableMap&lt;DWORD, DWORD&gt; cm; std::map&lt;DWORD, DWORD&gt; stdm; cm = stdm; </code></pre> <p>The problem is, the compiler is complaining with an error that doesn't make sense -- I've explicitly coded for what it's complaining about:</p> <pre><code>1&gt;c:\dev\proj\commonfunc.cpp(399) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::map&lt;_Kty,_Ty&gt;' (or there is no acceptable conversion) 1&gt; with 1&gt; [ 1&gt; _Kty=DWORD, 1&gt; _Ty=DWORD 1&gt; ] 1&gt; c:\dev\proj\templates.h(245): could be 'CleanableMap&lt;key_type,value_type&gt; &amp;CleanableMap&lt;key_type,value_type&gt;::operator =(const CleanableMap&lt;key_type,value_type&gt; &amp;)' 1&gt; with 1&gt; [ 1&gt; key_type=DWORD, 1&gt; value_type=DWORD 1&gt; ] 1&gt; c:\dev\proj\templates.h(250): or 'std::map&lt;_Kty,_Ty&gt; &amp;CleanableMap&lt;key_type,value_type&gt;::operator =(const std::map&lt;_Kty,_Ty&gt; &amp;)' 1&gt; with 1&gt; [ 1&gt; _Kty=unsigned long, &lt;--- where did it come up with that? 1&gt; _Ty=std::pair&lt;const DWORD,DWORD&gt;, &lt;--- where did it come up with that? 1&gt; key_type=DWORD, 1&gt; value_type=DWORD 1&gt; ] 1&gt; while trying to match the argument list '(CleanableMap&lt;key_type,value_type&gt;, std::map&lt;_Kty,_Ty&gt;)' 1&gt; with 1&gt; [ 1&gt; key_type=DWORD, 1&gt; value_type=DWORD 1&gt; ] 1&gt; and 1&gt; [ 1&gt; _Kty=DWORD, 1&gt; _Ty=DWORD 1&gt; ] </code></pre> <p>There 'could be' it mentions on line 245 doesn't make sense -- there is no assignment operator like that (well, it's private. Removing it completely doesn't change anything).</p> <p>The 'could be' it mentions on line 250 is the assignment operator that I defined, but it was somehow deduced some other non-matching template types. Where did it get those??</p> <p>Help!!! :)</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.
    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