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 6249569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:15:47+00:00 2026-05-24T13:15:47+00:00

I am trying to implement a logging factory and I have used an interface

  • 0

I am trying to implement a logging factory and I have used an interface so that I can swap loggers whenever I like.

Here is the interface

class ILogger
{
public:

    //Only allow string input. The entire ARC is going to be non-unicode.
    virtual void log(std::string message, eLogLevel level=DEBUG) = 0;

protected:
    virtual ~ILogger(void){};


private:
    // No one can create an ILogger as it is abstract but should also
    // disallow copying... why copy a logger? Only one per file. Besides want to 
    // force people to use the factory.
    /*ILogger(const ILogger&);
    ILogger& operator=(const ILogger&);*/ // REMOVED THIS BECAUSE OF ERROR

};

And here is a derived class (header)

class GenericLoggerImpl :
    public ILogger
{
public:
    virtual ~GenericLoggerImpl(void);
    virtual void log(std::string message, eLogLevel level=DEBUG);

private:
    GenericLoggerImpl(void); //USE THE FACTORY
    std::tr1::shared_ptr<GenericLogger> pImpl; //This is the implementation
    friend class LoggerFactory; // class LoggerFactory can now build these
};

And CPP

GenericLoggerImpl::GenericLoggerImpl(void):pImpl()
{
    pImpl = std::tr1::shared_ptr<GenericLogger> (new GenericLogger()); //This is the implementation
}

GenericLoggerImpl::~GenericLoggerImpl(void)
{
}

void GenericLoggerImpl::log(std::string message, eLogLevel level)
{
    pImpl->logMsg(message.c_str(),level);
}

Now here is the problem. See in the ILogger interface, I have commented out a private section of code? Well that is intended to stop anyone copying an ILogger derived class (like boost::noncopyable does). This makes sense (to me anyway) as it disallows separate instances of loggers from accessing the same file, and make the user go through my handy LoggerFactory.

When these lines are included then I get the following error:

genericloggerimpl.cpp(6) : error C2512: ‘ILogger’ : no appropriate default constructor available

What is that about? I do not want these objects to be copyable. How can I do that?

  • 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-24T13:15:48+00:00Added an answer on May 24, 2026 at 1:15 pm

    The existence of any user-defined constructor (which includes a copy-constructor) will prevent the compiler from generating a default-constructor. Your subclass GenericLogger relies on the existence of a default-constructor for ILogger (it is implicitly called, since it is not specified otherwise in the initialization-list of the constructor of GenericLogger), hence the error.

    To fix the problem, simple declare a protected trivial default constructor for ILogger:

    ILogger() {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm about to implement a logging class in C++ and am trying to decide
when trying to implement an Aspect, that is responsible for catching and logging a
I'm trying to implement a custom log4net logger/logmanager so that I can add a
I'm trying to implement my own stream manipulator inside my logging class. It's basically
I am trying to implement logging in my Python 2.7 applications and have found
I'm trying to implement slow query logging into my database class, but I'm getting
I am trying to implement the python logging handler TimedRotatingFileHandler . When it rolls
Hi I am trying to implement the java logging in my application. I want
I'm trying to implement ldapRealm on Glassfish 3.1. I can login fine with the
I'm trying to implement the logging approach at http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/ . I'm not sure how

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.