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.