How can I understand these macro function final output?

  Kiến thức lập trình

I got a piece of code like this.

#define MAKE_SINGLETON_1(classname, traits)          
        ;                                                   
    protected:                                              
        friend class base::Singleton<classname, traits>;    
    private:                                                
        classname(const classname&) = delete;               
        classname& operator=(const classname) = delete;     
    protected:                                              
        classname();                                        
        virtual ~classname();

#define MAKE_SINGLETON_2(classname)                   
        ;                                                   
    protected:                                              
        friend class base::Singleton<classname>;            
    private:                                                
        classname(const classname&) = delete;               
        classname& operator=(const classname) = delete;     
    protected:                                              
        classname();                                        
        virtual ~classname();

// selector
#define MAKE_SINGLETON_X(x, A, B, FUNC, ...) FUNC

// default parameter
#define MAKE_SINGLETON(...)                                 
            MAKE_SINGLETON_X(, ##__VA_ARGS__, MAKE_SINGLETON_1(__VA_ARGS__), MAKE_SINGLETON_2 (__VA_ARGS__))
}

In other classes, it is used like this

class CConnManager: public Singleton<CConnManager, Mutex>
{
    MAKE_SINGLETON( CConnManager, Mutex )
//other logic
}

I don’t understand what MAKE_SINGLETON finally produces. Could anybody help me explain? Thank you very much.

New contributor

user24501612 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT