'Incomplete type in nested name specifier

I tried to use incomplete type in nested name specifier as the following:

class A;

int b= A::c; // error: incomplete type ‘A’ used in nested name specifier

class A {
    static const int c=5;
};

There is says nothing about it in the 3.4.3/1 of N3797 working draft:

The name of a class or namespace member or enumerator can be referred to after the :: scope resolution operator (5.1) applied to a nested-name-specifier that denotes its class, namespace, or enumeration

So is that behavior implementation dependent?



Solution 1:[1]

I got the same error when accessing a member variable of a class that had been forward-declared in the header, but not included in the main from where I accessed it.

myClass.h

class FowardInclude; // has member "int x", but only forward-declared here

class MyClass {
public:
    void foo(int num);
}

main.cpp

#include "forwardInclude.h" // <-- This is the line I was missing
#include "myClass.h"

MyClass m;
m.foo(ForwardInclude::x);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zciurus