Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22085

Why do I get "does not name a type" when I access an `extern` defined variable

$
0
0

I have a .h file which contains class definition and an extern definition of a static variable The accompanying .cpp file declares and initializes this variable.

But when I try you access this variable in my main.cpp I get a does not name a type error. What am I doing wrong?

Contents of test.h file:

#pragma once
namespace Mine {
class Test {
  ...
};
} // namespace 
extern Mine::Test* variable;

Contents of test.cpp file:

Mine::Test* variable = nullptr;

Contents of main.cpp:

#include "test.h"

variable = new Mine::Test();

Viewing all articles
Browse latest Browse all 22085

Trending Articles