C + + (1) class template/constructor/catch Exception instance __ function

Source: Internet
Author: User
Tags function definition wrapper

Title:c++ (1) class template/constructor/catch Exception instance
Tag:cpp

In a header file, the general above writes the template class's declaration, below writes the template class the definition
one, class template 1. Statement of template class

Template<typename Tdatums,   
        typename Tworker = std::shared_ptr<worker<std::shared_ptr<tdatums> >>,
        typename tqueue = queue<std::shared_ptr<tdatums>>>
  class Wrapper
2. Use of template classes

There are three forms of parameters, which can be passed in any parameter. Creates an object of a class, Opwapper.

Op::wrapper<std::vector<op::D atum>> opwrapper;

Std::vector<op::D atum> should belong to the first form parameter 3. Definition of template function

A line in the code calls the Configue function.
There are four functions with the same name defined by configure, and the number of arguments passed in four is different, so you can duplicate the name.
Opwrapper.configure (Wrapperstructpose, Wrapperstructface, Wrapperstructhand, Wrapperstructinput, Wrapperstructoutput); second, the constructor 1. Statement

Explicit wrapper (const threadmanagermode threadmanagermode = threadmanagermode::synchronous); 2. Define

Constructor initializes some variables with a colon

    Template<typename Tdatums, TypeName Tworker, TypeName tqueue>, Wrapper<tdatums
    , Tworker;: Wrapper (const Threadmanagermode threadmanagermode):
        mthreadmanagermode{threadmanagermode},
        spVideoSeek{ STD::MAKE_SHARED<STD::p air<std::atomic<bool>, std::atomic<int>>> ()},
        MThreadManager {Threadmanagermode},
        mmultithreadenabled{true}
    {
        try
        {
            //It cannot is directly included in the constructor, otherwise compiler error for copying std::atomic
            = false;
            Spvideoseek->second = 0;
        }
        catch (const std::exception& e)
        {
            error (E.what (), __line__, __function__, __file__);
        }
    
3. destructor definition
Template<typename Tdatums, TypeName Tworker, TypeName tqueue>, Wrapper<tdatums tworker
 , tqueue>::~ Wrapper ()
 {function Body}
general definition of function
Template<typename Tdatums, TypeName Tworker, TypeName tqueue>
void Wrapper<tdatums, Tworker, Tqueue>: Disablemultithreading ()
{function Body}

In the class template, so the function definition should be added
Template<typename Tdatums, TypeName Tworker, typename tqueue> template keywords
And Wrapper<tdatums, Tworker, Tqueue>:: Class name three, catch exception

The Try...catch statement puts the code that throws the error in the try block, corresponds to a response, and then the exception is thrown.

   Template<typename Tdatums, TypeName Tworker, TypeName tqueue>
    void Wrapper<tdatums, Tworker, Tqueue>: Configure (const wrapperstructpose& wrapperstructpose,  const wrapperstructface& wrapperstructface, const wrapperstructinput& wrapperstructinput,const wrapperstructoutput&wrapperstructoutput)
    {
        try
        {
            Configure (Wrapperstructpose, Wrapperstructface, wrapperstructhand{},
                      Wrapperstructinput, wrapperstructoutput);
        }
        catch (const std::exception& e)
        {
            error (E.what (), __line__, __function__, __file__);
        }
    

The Configure function has only four inputs, but we look inside the function body and actually point to the function with five inputs and write a catch exception.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.