I have this logger.hpp file:
#ifndef _LOGGER_HPP_
#define _LOGGER_HPP_
#include "event.hpp"
class Logger {
public:
Logger();
~Logger();
Logger& operator<<(const Event& e);
private:
...
};
#endif
And this event.hpp file
#ifndef _EVENT_HPP_
#define _EVENT_HPP_
#include <string>
#include "logger.hpp"
class Event {
public:
Event();
~Event();
friend Logger& Logger::operator<<(const Event& e);
};
#endif
Well. In logger.hpp I turn on event.hpp, and in event.hpp I turn on logger.hpp.
Well, this, of course, is cyclic recursion .
I tried this:
1) In logger.hpp:
#ifndef _LOGGER_HPP_
#define _LOGGER_HPP_
#include "event.hpp"
class Event;
...
Does not work. The compiler tells me that event.hpp has an unrecognized type called Logger (and it's right, of course):
ISO C ++ Prohibits Declaring 'Registrar Without Type
The compiler points me to a line (in event.hpp) where there is a declaration of friendship.
2) In event.hpp:
#ifndef _EVENT_HPP_
#define _EVENT_HPP_
#include <string>
#include "logger.hpp"
class Logger;
...
. , logger.hpp , Event (, , ):
ISO ++ ""
( logger.hpp), .
... , ? , , , , .
??? ( , , :)).
Thankyou.