This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]