c++: how do i call a friend template function defined inside a class?

前端 未结 4 1232
感动是毒
感动是毒 2020-12-18 10:17

hi guys please help me with this function i got this example from my book, but i have no idea how to actually call the ticket function this is the code:

#in         


        
4条回答
  •  不思量自难忘°
    2020-12-18 10:42

    Why not make it static instead?

    #include 
    class Manager { 
    public:
        template 
        static int ticket()  
        { 
            return ++Manager::counter; 
        } 
        static int counter; 
    }; 
    
    int main()
    {
        Manager m;
        std::cout << "ticket: " << Manager::ticket() << std::endl;
    }
    

    Though really, it doesn't have to be a template either. I assume you needed information specifically about friend templates?

提交回复
热议问题