Note that there are some explanatory texts on larger screens.

plurals
  1. POMeaning of class(*)() in gcc
    primarykey
    data
    text
    <p>I'm having trouble understanding this compiler error. I wrote class(*)() in the post title because the class I am instantiating is called "opaque", but that name is not informative or relevant. It is a templatized Circular Buffer and some tests. I am using the opaque class to test the data structure with full class/struct types. I am also testing with primitives (int at the moment) and that test function does not give me this compiler error. There is more code than this, but I've provided what I think are the relevant sections. The full code is <a href="https://gist.github.com/3196485" rel="nofollow">here</a> if you are interested. </p> <p>gcc error:</p> <pre><code>tests.cpp: In function ‘bool opaque_fill_test(int)’: tests.cpp:97:23: error: no matching function for call to ‘CircBuf&lt;opaque&gt;::remove(opaque (*)())’ </code></pre> <p>tests.cpp:</p> <pre><code>struct opaque { int id; opaque(int n): id(n) {} opaque operator=(const opaque &amp;o) { this-&gt;id = o.id; } }; opaque rcv(); CircBuf&lt;opaque&gt; c(size); for (int i=0; i&lt;size; i++) { if ( c.remove(&amp;rcv)) { if (rcv.id != i ) { cout &lt;&lt; "wrong value: " &lt;&lt; rcv &lt;&lt; " " &lt;&lt; "should be: " &lt;&lt; i &lt;&lt; endl; return false; } } else { cout &lt;&lt; "remove fail at i=" &lt;&lt; rcv &lt;&lt; endl; return false; } } </code></pre> <p>CircBuf.h:</p> <pre><code>template&lt;typename T&gt; class CircBuf { ... template&lt;typename T&gt; bool CircBuf&lt;T&gt;::remove(T *t) { ... *t = data[front]; ... </code></pre> <p>if i declare an opaque* and pass that to remove instead:</p> <pre><code>opaque rcv(); opaque* p = &amp;rcv; for (int i=0; i&lt;size; i++) { if ( c.remove(p)) { ... ... </code></pre> <p>i get a similar error:</p> <pre><code>tests.cpp: In function ‘bool opaque_fill_test(int)’: tests.cpp:96:16: error: cannot convert ‘opaque (*)()’ to ‘opaque*’ in initialization </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.
    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