How to create templatized wrapper class in C++

john paul 41 Reputation points
2020-11-15T15:47:29.907+00:00

Hello All,

I am invoking a function from many places in the project. Only difference is that one of the parameters is of different data types.

I was asked to create a templatized wrapper class. Could someone help me how to do that?

I am invoking the below function from different places. Here when invoking this function, the second parameter (f_strCallid) might be string, int, unsigned long etc.

std::shared_ptr<CCallListImpl> CCallListImpl::handleCallCollectionEvents(Events f_eCallEvent, const std::string& f_strCallid)
{
shared_ptr<CCallListImpl> l_hCallObj = nullptr;

return l_hCallObj;

}

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,758 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 9,771 Reputation points Microsoft Vendor
    2020-11-16T05:21:49.35+00:00

    Hi,

    According to the your description, I suggest you could try the following code:

    template <typename T>  
    std::shared_ptr<CCallListImpl>  
    CCallListImpl::handleCallCollectionEvents(Events f_eCallEvent, const T& f_strCallid)  
    {  
        shared_ptr<CCallListImpl> l_hObj = nullptr;  
      
        return l_hObj;  
    }  
    

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.