Possible Duplicate:
How to initialize a const field in constructor?
I have this class:
class Foo {
private:
...
public:
Foo() : ... {}
// no other constructors
...
};
and another one which holds a Foo member by reference:
class Bar {
private:
const Foo& m_foo;
...
public:
Bar(const Foo& foo);
// no other constructors
};
My question is: how do i initialize the Bar::m_foo reference at the constructor?
Thanks!
In the constructor initialization list:
constand reference members must be initialized in the initialization list, in this case the member is both.