public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: could not convert `obj(5)' to `obj &'
@ 2003-11-11 17:20 Lev Assinovsky
  0 siblings, 0 replies; 3+ messages in thread
From: Lev Assinovsky @ 2003-11-11 17:20 UTC (permalink / raw)
  To: Jon Vance, gcc-help

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?
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: could not convert `obj(5)' to `obj &'
  2003-11-11 16:45 Jon Vance
@ 2003-11-12 11:40 ` Nathan Sidwell
  0 siblings, 0 replies; 3+ messages in thread
From: Nathan Sidwell @ 2003-11-12 11:40 UTC (permalink / raw)
  To: Jon Vance; +Cc: gcc-help

Jon Vance wrote:
> 
> 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:

> void printit(obj& o)
void printit (obj const & o)
> {
>  printf("%d\n", o.i);
> }

> 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
you cannot bind a temporary to a non-constant reference

nathan


-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
          The voices in my head said this was stupid too
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk


^ permalink raw reply	[flat|nested] 3+ messages in thread

* could not convert `obj(5)' to `obj &'
@ 2003-11-11 16:45 Jon Vance
  2003-11-12 11:40 ` Nathan Sidwell
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Vance @ 2003-11-11 16:45 UTC (permalink / raw)
  To: gcc-help


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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-11-12 11:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-11 17:20 could not convert `obj(5)' to `obj &' Lev Assinovsky
  -- strict thread matches above, loose matches on Subject: below --
2003-11-11 16:45 Jon Vance
2003-11-12 11:40 ` Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).