Const in default function arguments?
Eric Lemings
eric@lemings.com
Thu Apr 3 22:10:00 GMT 2003
[elemings@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@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@cyberia c++]$ diff Test01.cpp Test02.cpp
12c12
< void G (const Foo& f = Bar ()) {
---
> void G (Foo& f = Bar ()) {
[elemings@cyberia c++]$ g++ -g -Wall -pedantic -c Test01.cpp
[elemings@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?
More information about the Gcc-help
mailing list