This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Const in default function arguments?
- From: "Eric Lemings" <eric at lemings dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Thu, 3 Apr 2003 15:10:30 -0700
- Subject: Const in default function arguments?
[elemings at cyberia c++]$ g++ --version
g++ (GCC) 3.2.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[elemings at cyberia c++]$ more Test01.cpp
#include <iostream>
struct Foo {
int i;
};
struct Bar: public Foo {
// empty class body
};
void G (const Foo& f = Bar ()) {
std::cout << f.i << std::endl;
}
[elemings at cyberia c++]$ diff Test01.cpp Test02.cpp
12c12
< void G (const Foo& f = Bar ()) {
---
> void G (Foo& f = Bar ()) {
[elemings at cyberia c++]$ g++ -g -Wall -pedantic -c Test01.cpp
[elemings at cyberia c++]$ g++ -g -Wall -pedantic -c Test02.cpp
Test02.cpp:12: default argument for `Foo&f' has type `Bar'
Why won't the non-const version compile?