I already searched for questions about forward declaration but couldn't find a answer to my case.
I have a class Foo:
Foo.h
#pragma once
#include <string>
namespace aaa::xxx::yyy::zzz
{
class Foo {
public:
Foo() = default;
std::string get_value() const
{
return m_value;
}
void set_value(const std::string& value)
{
m_value = value;
}
private:
std::string m_value{};
};
}
This class Foo
is used in annother class Bar
:
Bar.h
#pragma once
namespace aaa::xxx::yyy::zzz
{
class Foo;
}
namespace aaa::bbb::ccc::ddd
{
using Foo = aaa::xxx::yyy::zzz::Foo;
class Bar
{
public:
Bar() = default;
Foo get_foo() const;
private:
Foo m_foo{};
};
}
Bar.cpp
#include "Bar.h"
#include "Foo.h"
namespace aaa::bbb::ccc::ddd
{
using Foo = aaa::xxx::yyy::zzz::Foo;
Foo Bar::get_foo() const
{
return m_foo;
}
}
Now i dont know what i did wrong with the forwad declaration. I declared class Foo before class Bar
with its namespace but still its states that class Foo
is undefined.
So the Question is how to forward class Foo correctly?
EDIT:
Changing Foo m_foo{};
to Foo m_foo;
as suggested still produces the same error.