Couple of things.
- You should include header guards:
Example:
//Foo.H
#ifndef __FOO_H__
#define __FOO_H__
...
...
#endif
- Bar.H should be including Foo.H if its implementing a constructor that requires knowledge of Foo's implementation. (You are)
- This is another problem you will likely run into later.
- The static member does NOT have to be initialized in global scope, it has to be defined once and only once.
Despite what the other answers state, main is a horrible place to do this. Doing so requires everyone who ever uses this class to have know to do this in their main. How the heck would I know to define static constants in my main when I want to use your header (or even another developer on your team or for another block of code) ? The answer is I wouldn't. It's a lazy practice that will form a bad habit. And don't even get me started on static initialization/destruction fun.
You can't put it in Foo.H because doing so would result in linker errors from the redefinition by every compilation unit that includes your header.
A far better place to do this is in a newly created Foo.[c|.cxx|.cpp|.cc] (whatever suffix you use).
Does main work? Yes it works... for you right now. Will it cause issues later? Probably. Is it good form and a solution to be remembered? Absolutely not.
Best Answer:
//Foo.C (NOT MAIN)
#include<Foo.h>
int Foo::m = 0;
What you should also notice is nothing about my answer has anything do with a second class using it in its constructor. Were I to have the points, I would edit the title of your question because it has nothing to do with constructors or class member functions. You are talking about static class methods/functions not member functions/methods.