keith@cecil.UUCP (03/07/86)
A member of a const argument cannot be used as a const argument in a
function call:
class Foo { int i; };
class Bar {
Foo foo;
public:
void g(const Foo&);
void f(const Bar& b) { g(b.foo); } // gets error
};
"constbug.c", line 7: error: address of member Bar::foo of const Bar
Is this a bug in C++ Release 1.0 or a "feature"?
Incidentally, you can get around this with an explicit cast:
{ g(((Bar*)&b)->foo); }
--
---
Keith Gorlen
Computer Systems Laboratory
Division of Computer Research and Technology
National Institutes of Health
Bethesda, MD 20892
phone: (301) 496-5363
uucp: {decvax!}seismo!elsie!cecil!keith
bs@alice.UucP (Bjarne Stroustrup) (03/09/86)
> From: keith@cecil.UUCP (keith gorlen) > Newsgroups: net.lang.c++ > Subject: Is this a C++ bug? > Organization: NIH-CSL, Bethesda, MD > > A member of a const argument cannot be used as a const argument in a > function call: > > class Foo { int i; }; > > class Bar { > Foo foo; > public: > void g(const Foo&); > void f(const Bar& b) { g(b.foo); } // gets error > }; > > "constbug.c", line 7: error: address of member Bar::foo of const Bar > > Is this a bug in C++ Release 1.0 or a "feature"? It is a 1.0 bug (not a language bug). Sorry. My cfront compiles it without a hickup.