2
votes

I'm having a problem with forward declarations in a nested namespace. I put a forward declaration for a class or struct in a nested namespace and when I try to use it in the parent of that namespace I get an error. I don't know what to do.

This is what the code looks like:

#include "Data\Types.hpp"

namespace GameEngine
{
    class Console
    {
    public:
        class Renderer : public RenderComponent2D
        {
        public:
            Renderer(Console*, const GameEngine::DataProcessing::FontData*);
//...

and in Data\Types.hpp:

namespace GameEngine
{
    namespace DataProcessing
    {
        struct FontData;
//...

and the error MinGW gives me is :

'FontData' in namespace 'GameEngine::DataProcessing' does not name a type

I appreciate any help or suggestions with this problem.

2
Try just const DataProcessing::FontData *. - Kerrek SB
Post a small program that reproduces the problem. - Cheers and hth. - Alf
@Rob thanks for trying the code, I still don't know what the issue is. It might be some recursive include somewhere, I've gotten that a few times on large projects. - Jim
A small note: You should use the forward slash in the #include, even under Windows. As is, you produce undefined behaviour, and there might some (current or future) compiler which doesn't like it (because it doesn't special-case string constants in #include directives and thus interprets \T as escape sequence). Not to mention that one day you might want to port your program to a different system which doesn't use backslashes as directory separators. - celtschk

2 Answers

2
votes

I had a similar issue recently that turned out to be an unclosed namespace, e.g.

namespace A {
    namespace B {
        class C {};
// failed to close both namespaces properly here

What threw me off the trail a bit is that the unclosed namespace was actually in a secondary file being included in my cpp file. Try poking around in your headers to see if any of them have unclosed namespaces.

1
votes

May be problem in declaration of method. You are already inside GameEngine namespace:

namespace GameEngine
{
    class Console

But in declaration you use this namespace too :

 Renderer(Console*, const GameEngine::DataProcessing::FontData*);

Try it without GameEngine :

 Renderer(Console*, const DataProcessing::FontData*);