 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Stephan Br?nnimann Guest
|
Posted: Fri Nov 19, 2004 3:07 pm Post subject: Reference to a forward declared class as class member? |
|
|
Dear all
is the definition of Foo::bar_, which is a reference to
a forward declared class, well defined according to the standard?
My gut feel tells me that it's not and that it works in g++ by
accident only.
foo.h
=====
class Bar; // in bar.h
class Foo {
public:
Foo(Bar& bar);
private:
Foo& operator=(const Foo&); // not implemented
private:
Bar& bar_;
};
foo.cc
======
#include "bar.h"
Foo::Foo(Bar& bar) : bar_(bar)
{
// empty
}
Stephan Brönnimann
[email]broeni (AT) osb-systems (DOT) com[/email]
Open source rating and billing engine for communication networks.
P.S. I know I can use a pointer to Bar instead.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Sat Nov 20, 2004 10:36 am Post subject: Re: Reference to a forward declared class as class member? |
|
|
Stephan Br?nnimann wrote:
| Quote: | Dear all
is the definition of Foo::bar_, which is a reference to
a forward declared class, well defined according to the standard?
|
Yes.
| Quote: | My gut feel tells me that it's not and that it works in g++ by
accident only.
|
I wish I had accidents like that more...
V
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Bob Hairgrove Guest
|
Posted: Sat Nov 20, 2004 6:19 pm Post subject: Re: Reference to a forward declared class as class member? |
|
|
On 19 Nov 2004 10:07:39 -0500, [email]broeni (AT) hotmail (DOT) com[/email] (Stephan Br?nnimann)
wrote:
| Quote: | Dear all
is the definition of Foo::bar_, which is a reference to
a forward declared class, well defined according to the standard?
My gut feel tells me that it's not and that it works in g++ by
accident only.
foo.h
=====
class Bar; // in bar.h
class Foo {
public:
Foo(Bar& bar);
private:
Foo& operator=(const Foo&); // not implemented
private:
Bar& bar_;
};
foo.cc
======
#include "bar.h"
Foo::Foo(Bar& bar) : bar_(bar)
{
// empty
}
|
It is legal AFAICS. See the last example given in section 9.1.2 of the
standard, which uses references to forward-declared, but not defined,
classes.
--
Bob Hairgrove
[email]NoSpamPlease (AT) Home (DOT) com[/email]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|