Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3675748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:00:57+00:00 2026-05-19T03:00:57+00:00

I have this file logger.hpp: #ifndef _LOGGER_HPP_ #define _LOGGER_HPP_ #include event.hpp // Class definitions

  • 0

I have this file logger.hpp:

#ifndef _LOGGER_HPP_
#define _LOGGER_HPP_

#include "event.hpp"

// Class definitions
class Logger {
public:
    /*!
     * Constructor
     */
    Logger();
    /*!
     * Destructor
     */
    ~Logger();
    /*!
     * My operator
     */
    Logger& operator<<(const Event& e);
private:
    ...
};

#endif

And this file event.hpp

#ifndef _EVENT_HPP_
#define _EVENT_HPP_

#include <string>

#include "logger.hpp"

// Class definitions
class Event {
public:
  /*!
   * Constructor
   */
  Event();
  /*!
   * Destructor
   */
  ~Event();

  /* Friendship */
  friend Logger& Logger::operator<<(const Event& e);
};

#endif

Well. In logger.hpp I include event.hpp and in event.hpp I include logger.hpp.

  • I need to include event.hpp because in logger.hpp I need to define the operator.

  • I need to include logger.hpp because, in event.hpp, of the friendship to be defined in the class Event.

Well this is, of course, a cyclic recursion.

I tried this:

1) In logger.hpp:

#ifndef _LOGGER_HPP_
#define _LOGGER_HPP_

#include "event.hpp"

class Event; // Forward decl

// Class definitions
...

Does not work. Compiler tells me that in event.hpp there is a not recognized type called Logger (and he is right of course):

ISO C++ forbids declaration of
‘Logger’ with no type

Compiler indicates me the line (in event.hpp) where there is the friendship declaration.

2) In event.hpp:

#ifndef _EVENT_HPP_
#define _EVENT_HPP_

#include <string>

#include "logger.hpp"

class Logger; // Forward decl

// Class definitions
...

Does not work. Compiler tells me that in logger.hpp there is a not recognized type called Event (and, again, it is right for obvious reasons):

ISO C++ forbids declaration of ‘Event’
with no type

Compiler indicates me the line (in logger.hpp) where there is the operator declaration.

Well… do not know how to face this? I tried everything, I put forward declarations everywhere, but, of course, they are not of any help.
How to solve this??? (I suppose a best practice exists, better I hope so 🙂 ).

Thankyou.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:00:57+00:00Added an answer on May 19, 2026 at 3:00 am

    Get rid of the #include "event.hpp" in logger.hpp – the forward declaration of class Event should be enough if all you need is a reference to an Event object in the function prototype:

    #ifndef _LOGGER_HPP_
    #define _LOGGER_HPP_
    
    // #include "event.hpp"  // <<-- get rid of this line
    
    class Event; // Forward decl
    
    // Class definitions
    ...
    

    The implementation of class Logger in logger.cpp will likely need to include event.hpp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this GIF file on my desktop (it's a 52 card deck
So I have this .htaccess file in the /blog/ folder on my webserver and
I have this tiny Qt project with a project file like this: TEMPLATE =
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
This is driving me crazy. I have this one php file on a test
I have this function to read in all ints from the file. The problem
I have some code that effectively does this : File file = new File(C:\\Program
I have this on line 56 in my environment.rb: I18n.load_path += Dir[ File.join(RAILS_ROOT, 'lib',
I have a generated txt file. This file has certain lines that are superfluous,
I have this: Dim myTemp As String myTemp = System.DateTime.Now().ToString(MMMddyyyy_HHmmss) & .pdf System.IO.File.Copy(myFile, c:\

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.