Thread: how to make an inherited constructor private?

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    19

    how to make an inherited constructor private?

    i have a base class and every thing is inherited from it .

    i want to make that base class private but when i try the inherited class complains when it trys to pass arguments back to it from when i make it .
    anyway i can make it private


    the base class contructor has a lot of info for setting up the class so , im not sure if i can make it abstract

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What do you mean by "make that base class private"? As in you are trying to use private inheritance?
    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

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    19
    Quote Originally Posted by laserlight View Post
    What do you mean by "make that base class private"? As in you are trying to use private inheritance?
    just the constructor

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by thedodgeruk
    just the constructor
    Oh, then the solution is simple: just don't implement a similiar constructor in the derived class. Someone who wants to construct a derived class object has to use the derived class constructors, even though these in turn invoke a base class constructor. If you really do want to make the base class constructor non-public yet accessible from the derived class constructor(s), then declare that base class constructor as protected.
    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

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    19
    Quote Originally Posted by laserlight View Post
    Oh, then the solution is simple: just don't implement a similiar constructor in the derived class. Someone who wants to construct a derived class object has to use the derived class constructors, even though these in turn invoke a base class constructor. If you really do want to make the base class constructor non-public yet accessible from the derived class constructor(s), then declare that base class constructor as protected.

    cheers , i made it protected , i thought what i wanted was not possible , was trying to make it like the way a singleton works , but could not get it right

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    uh, constructors aren't inherited... I'm not sure what you are worrying about.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Establishing 'make clean' with GNU make
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 04-11-2009, 09:10 AM
  2. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 09:51 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 01:05 PM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM