This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: implicit type cast problem of reference of ponter to const type
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: Steve Yee <yitonglu at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Sat, 16 Apr 2005 15:56:27 +0100
- Subject: Re: implicit type cast problem of reference of ponter to const type
- References: <338deebe05041522134e7e4378@mail.gmail.com>
On Sat, Apr 16, 2005 at 01:13:46PM +0800, Steve Yee wrote:
> the following code can not compile. is it due to the standard?
Yes, this is not valid C++. int* -> const int* creates a temporary and
you can't bind a non-const reference to a temporary.
You might mean
void testfun(int * const & pr)
or just
void testfun(int * pr)
GCC is correct to reject this code so if you want more information you
should try somewhere like comp.lang.c++
> void testfun(const int *&pr)
> {
> }
>
> main()
Should be "int main()"
> {
> int *p;
> testfun(p);
> }
hope that helps,
jon
--
"Democracy is the theory that the common people know what they want, and
deserve to get it good and hard."
- H.L. Mencken