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

  • SEARCH
  • Home
  • 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 6233155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:14:50+00:00 2026-05-24T10:14:50+00:00

Once in a while some functionality has to be conditionally compiled. For example, there’s

  • 0

Once in a while some functionality has to be conditionally compiled. For example, there’s class Logger that is only used when WITH_LOGGING macro is #defined:

// Logger.cpp
#ifdef WITH_LOGGING
#include <Logger.h>
// several hundred lines
// of class Logger
// implementation
// follows
#endif

which is not very convenient – unless the reader scrolls through the file he can’t be sure that the matching #endif is position at the end of file and so the whole file contents is excluded with the #ifdef. I’d prefre to have something like this:

// Logger.cpp
#ifndef WITH_LOGGING
#GetOutOfThisFile
#endif
#include <Logger.h>
// several hundred lines
// of class Logger
// implementation
// follows

so that it’s clear that once the WITH_LOGGING is not #defined the compiler just skips the rest of the file.

Is something like that possible in C++?

  • 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-24T10:14:51+00:00Added an answer on May 24, 2026 at 10:14 am

    An easy way to clarify this would be to put the implementation in another file which is included:

    file Logger.cpp:

    #ifdef WITH_LOGGING
     #include <Logger.h>
     #include "logger.impl"
    #endif
    

    file logger.impl:

    // several hundred lines
    // of class Logger
    // implementation
    // follows
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been busy diving into lambda expressions recently, and there's some specific functionality that
I have several server processes that once in a while respond to messages from
Im using Visual studio 2008. Every once in a while files that exist in
Probably everyone ran into this problem at least once during development: while(/*some condition here
If I have a class that I expect to be used in thousands of
Does anyone know of a class in Java that has a list of elements,
Every once in a while I will paste in some code and it will
Is it possible to query the database only once while the page loads in
Once in a while you stumble over a technical article where creating and declaring
Every once in a while, typically when I stop debugging in our UI assembly,

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.