Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The error message tells you what you're trying to pass. With automatic conversions and whatnot, that doesn't mean the function must have exactly that signature.</p> <p><code>int&amp;</code> here just means that the parameter you've provided is an lvalue, and so it <em>could</em> be passed as a non-const reference. A function can match with that parameter as an <code>int&amp;</code>, <code>const int&amp;</code>, <code>int</code>, <code>long</code>, <code>const float&amp;</code>, etc.</p> <blockquote> <p>the point is that if instead of z i write 100 it works.</p> </blockquote> <p>That's interesting. I can't immediately think of a way to write a function that accepts an integer literal, but not an integer variable. The following code compiles, of course:</p> <pre><code>struct SDL_Surface; struct SDL_Rect; struct display { void foo(SDL_Surface* img, int x=0, int y=0, SDL_Rect* clip=0) {} }; int main() { display d; int z = 0; SDL_Surface *p = 0; d.foo(p,z,100); } </code></pre> <p>So there must be something else you haven't mentioned yet, which causes the issue.</p> <p>Edit: visitor and Charles Bailey (in a comment) have the answer. The defaults are missing from your declaration of the function, so as far as the compiler is concerned you are trying to call a 4-parameter function with 3 arguments. The <code>&amp;</code> is not the problem.</p> <p>For future reference: when James McNellis asked you for "the" declaration of your function, he meant the declaration which is visible in the translation unit making the call. In your pastebin code, the <em>definition</em> is not visible in that translation unit, and the compiler cannot reach in to a completely different .cpp file and realise that the function is supposed to have parameter defaults. In C++, default values are set up in the calling code, for reasons to do with how calling conventions work.</p>
 

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