Wednesday, October 19, 2005

Re: New kid in the block

Yes you can make constructor private, That's the startegy we used to create a singleton class. You can't make destructor private coz that creates problem. Here is the example
 

class Logger
{
        private :
                string debugLogFileName ;

                /* File streams */
                ofstream *debugLogStream ;
                /* private constructor to make it singleton */
                Logger() ;

                static Logger *loggerObj ;
                public :
                void setDebugLogFileName( string debugLog ) ;
              /* Methods for Debug log */
                void printDebug( const char *logMessage ) ;
                void printInfo( const char *logMessage ) ;
                void printError( const char *logMessage ) ;
                void closeLog() ;
                ~Logger() ;
                static Logger* instance() ;
       };

 

here I have decleared a startic fuction that i will use to create object.



 
On 10/20/05, rits <rahul.dhi@gmail.com> wrote:

bhupinder i have read that u cannot declare the constructors in
private.it means the compiler will always give error even when u
declare the constructor in private even if there is no
inheritance.please check if i am correct.


0 Comments:

Post a Comment

<< Home