public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* initialization of non-const reference
@ 2000-09-22  8:23 Sjoerd Adema
  2000-09-22 20:57 ` llewelly
  0 siblings, 1 reply; 2+ messages in thread
From: Sjoerd Adema @ 2000-09-22  8:23 UTC (permalink / raw)
  To: gcc

Hi,

I am in big trouble :-(

My databasesoftware contains the following code:

class genericObj {
...
public:
	genericObj( ..., const SetObj& set );
...
};

class myObj : public genericObj {
...
public:
	myObj() : genericObj(..., SetObj() ) {}
...
};

when I compile the sourcecode I get the compiler error: initialization
of non-const reference type `class SetObj &`

Bjarne Stroustrup tells in his book section 10.4.10 "A temporary can be
used as an initializer for a CONST reference or a named object."

Tons of code is written like this, so it is a huge problem for me.

Am I missing something here ? I use Suse Linux 6.4 with gcc 2.95-2

Any help would be highly appreciated.

Sjoerd Adema
AXY Management Systemen
The Netherlands
sadema@axy.nl

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

* Re: initialization of non-const reference
  2000-09-22  8:23 initialization of non-const reference Sjoerd Adema
@ 2000-09-22 20:57 ` llewelly
  0 siblings, 0 replies; 2+ messages in thread
From: llewelly @ 2000-09-22 20:57 UTC (permalink / raw)
  To: sadema; +Cc: gcc

Sjoerd Adema <sjoerd@axy.nl> writes:

> Hi,
> 
> I am in big trouble :-(
> 
> My databasesoftware contains the following code:
> 
> class genericObj {
> ...
> public:
> 	genericObj( ..., const SetObj& set );
> ...
> };
> 
> class myObj : public genericObj {
> ...
> public:
> 	myObj() : genericObj(..., SetObj() ) {}
> ...
> };

Please supply a complete example; the ...s you obscure
  the problem.

With gcc 2.95.2, the following compiles with no errors:

struct Foo
{};

struct Base
{
  Base(Foo const& c):i(c){}
  Foo i;
};

struct Derived:Base
{

  Derived(Foo const& c)
    :Base(c){}
};

int main()
  {
    Derived d(Foo());
  }


> 
> when I compile the sourcecode I get the compiler error: initialization
> of non-const reference type `class SetObj &`
> 
> Bjarne Stroustrup tells in his book section 10.4.10 "A temporary can be
> used as an initializer for a CONST reference or a named object."
> 
> Tons of code is written like this, so it is a huge problem for me.
> 
> Am I missing something here ?

Yes - an example sufficient to reproduce the bug. :-)

> I use Suse Linux 6.4 with gcc 2.95-2
> 
> Any help would be highly appreciated.
> 

Thank you for your bug report.

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

end of thread, other threads:[~2000-09-22 20:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-22  8:23 initialization of non-const reference Sjoerd Adema
2000-09-22 20:57 ` llewelly

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).