I have the following code:
Foo.h:
include "Bar.h"
class Bar;
class Foo {
const Bar mBar;
public:
Foo(const Bar &bar);
};
Foo.cpp:
#include "Foo.h"
Foo::Foo(const Bar &bar) : mBar(bar) {}
I receive the following compilation error:
'Foo::mBar' uses undefined class 'Bar'
Is const definition not allowed in implementation file?
Obviously in this case I could move ctor implementation into header file.
But What is an alternative if I want to call Bar ctor which may take arguments requiring forward declaration instead of copy ctor and still keep Bar member variable constant? So for example:
Foo.h:
include "Bar.h"
class Bar;
class BaraParams;
class Foo {
const Bar mBar;
public:
Foo(const BarParams &barParams);
};
Foo.cpp:
#include "Foo.h"
Foo::Foo(const BarParams &barParams) : mBar(barParams) {} //call bar ctor
Bar.h:
include "BarParams.h"
class Bar{
public:
Bar(const BarParams &barParams);
};
Or am I not doing this right? I don't even know if this is a good idea.