Q:

Extern pointer initialization

I have this class:
Logger.h
class Logger{

    std::string filename;
    std::ofstream fileStream;

    /*Some methods ...*/
};

extern Logger* log;

In another header file i have included the *log definition:
Foo.h
#include "Logger.h"

class Foo{
    Logger* log;

    /*Other code*/
};

But if in Foo.cpp file i try to do this:
log = new Logger();

the compiler give me an error, any idea?

A:

First, variables declared as external must be defined. So you need to have
Logger *log;

in Logger.cpp. You can also initialize it there like this:
Logger *log = new Logger();

Second, you don't need any more declarations, that is you just need to include Logger.h, no need to declare another Logger variable in Foo.h, just use log from Logger.h.

