Thread: Is this bad programming practice?

  1. #1
    Registered User
    Join Date
    Jan 2007

    Question Is this bad programming practice?

    Is it bad programming practice to make a class that has a protected Constructor/Destructor?

    I want this class to be like an abstract class (can't create instance) but it will not have any pure virtual (abstract) methods, only methods that will be derrived by other classes and methods that will be used by derived classes.

    Last edited by avalanche333; 03-31-2007 at 06:34 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    In C++ Common Knowledge Item 33, Stephen Dewhurst suggests that if you have "no reasonable candidate for a pure virtual function but still want the class to act like abstract base", you can either make its default and copy constructor protected, or you can make its destructor a pure virtual, in which case it does not matter if it is public or protected. If you choose the latter, remember to implement the base class destructor anyway, as the derived class destructor will still call it implicitly.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bad practice or acceptable?
    By Noose in forum C++ Programming
    Replies: 6
    Last Post: 06-09-2004, 01:43 AM
  2. Replies: 11
    Last Post: 11-13-2002, 01:29 PM
  3. Bad Practice??
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-25-2001, 08:37 AM
  4. good news and bad news
    By Garfield in forum A Brief History of
    Replies: 25
    Last Post: 10-27-2001, 07:31 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM