Custom class object in Initialization list
- by Michael
I have a class Bar:
class Bar
{
public:
Bar(void);
~Bar(void);
};
And a class Foo that gets a reference to Bar object as a constructor parameter and needs to save it in a private member bar_ :
class Foo
{
private:
Bar& bar_;
public:
Foo(Bar& bar) : bar_(bar) {}
~Foo(void) {}
};
This doesn't compile :
overloaded member function not found in 'Parser'
missing type specifier - int assumed. Note: C++ does not support default-int
Now i suspect couple of things that i need to assure, the second error is for Bar& bar_; declaration in Foo. Do i need to use an explicit constructor when declaring bar_ ?
I am interested in learning how the compiler works regarding this matter, so a detailed explanation would be highly appreciated.
Thanks.