Custom class object in Initialization list

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2012-06-08T10:37:03Z Indexed on 2012/06/08 10:40 UTC
Read the original article Hit count: 248

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about constructor