could not convert `obj(5)' to `obj &'
Lev Assinovsky
LAssinovsky@algorithm.aelita.com
Tue Nov 11 17:20:00 GMT 2003
You have to use void printit(const obj& o)
since you pass obj(n) which is considered as a temporary.
----
Lev Assinovsky
Aelita Software Corporation
O&S InTrust Framework Division, Team Leader
ICQ# 165072909
> -----Original Message-----
> From: Jon Vance [mailto:mail@jonvance.com]
> Sent: Tuesday, November 11, 2003 7:45 PM
> To: gcc-help@gcc.gnu.org
> Subject: could not convert `obj(5)' to `obj &'
>
>
>
> I have a bunch of code that used to compile under an older
> version of gcc,
> and will not do so using 2.96. Here is a very simple example of the
> problem I am having:
>
> CODE:
>
> #include <stdio.h>
>
> struct obj
> {
> int i;
>
> obj(int n) : i(n) {}
> };
>
> void printit(obj& o)
> {
> printf("%d\n", o.i);
> }
>
> main()
> {
> printit(obj(5));
> }
>
>
>
> COMPILER ERROR:
>
> g++ t.cpp -o t
> t.cpp: In function `int main ()':
> t.cpp:17: could not convert `obj(5)' to `obj &'
> t.cpp:11: in passing argument 1 of `printit (obj &)'
> make: *** [t] Error 1
>
>
>
> Any ideas?
>
>
More information about the Gcc-help
mailing list