This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: initialization of non-const reference
- To: sadema at axy dot nl
- Subject: Re: initialization of non-const reference
- From: llewelly at edevnull dot com
- Date: 22 Sep 2000 20:58:41 -0600
- Cc: gcc at gcc dot gnu dot org
- References: <39CB72CF.E6B1666C@bonnie.axy.nl>
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.