0

I am trying to declare a static variable in console.h and define it in console.cpp. the line calling the variable is:

     ok = CheckIoEditMinMax(0,Console::_tabsize, curpos, 0, insert,
     20-Console::_tabsize,20, offset) && ok;

I have know been able to pass it, but the compiler doesn't like the way I am doing it. For example I have declared it like this:

/*Edited*/
namespace cio{
  class Console{ 
    public:  
    static unsigned int _tabsize; //Under public so it can be reached by the main.
                                  //inside the console class in cio namespace
    };
}    

And then defined in the cpp file like this:

/*Edited - Also No it is not Const */
namespace cio{
   unsigned int Console::_tabsize = 4;
}

But the compiler still doesn't like this and is saying this:

console.cpp:8:32: error: âunsigned int cio::Console::_tabsizeâ is not a 
                  static member of âclass cio::Consoleâ

I don't Know why its doing this or even where to figure it out. Also it is a little bit odd that the compiler would say this don't you think?

Saulius
  • 21
  • 1
  • 9

1 Answers1

2

Only the declaration of the member variable needs to include the static specifier.

struct Foo
{
    static int value_;
};

// static specifier cannot be used here. 
int Foo::value_ = 1;

In this case if _tabsize does not change you can declare it as const and assign a value to it in the class definition. If you do not there is no need to provide a definition.

struct Foo
{
    static const int value_ = 1;
};
Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74