Re: compiler error

From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 02/15/04


Date: Sun, 15 Feb 2004 01:11:29 +0000

In message <157t20h36fkm1vmr0mq7jolbq28t78a3is@4ax.com>, Robert W Hand
<rwhand@NOSPAMoperamail.com> writes
>On Sat, 14 Feb 2004 21:54:47 +0000 (UTC), "Jason"
><jason.carney1@btinternet.com> wrote:
>
>>int a, b, c;
>>//place values in a,b,c using atoi

read his code, specifically the comment above.

>>x.func(a, b, c);
>>
>>And the compiler says this:
>>
>>no matching function for call to 'XClass::func(int&, int&, int&)
>>candidates are: int XClass::func(int, int, int);
>>
>>What might have gone wrong?
>>
>>Clearly I have declared a,b,c ok and not done much with them except set them
>>to certain values. Why would the compiler complain that I am calling the
>>function using references when I am not?
>
>It is undefined behavior.
He said he had omitted the initialisation code. Anyway even if he
actually left it out, the compiler would not do what he reports.

> Automatic variables that are not
>initialized have indeterminant values. You are not allowed to assign
>their values to other variables. But you can assign the objects a, b,
>c to references to int without specifying values for a, b, c. So it
>may be that your compiler has noted the undefined behavior and warned
>you about it.
>
>Perhaps someone will have a better idea.
>
>Best wishes,
>
>Bob

-- 
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects