我有一个将大小作为模板参数的类(live demo):
template <std::size_t SIZE> class A
{
char b[SIZE];
}
Run Code Online (Sandbox Code Playgroud)
它具有用于不同目的的多个构造函数:
using const_buffer_t = const char (&)[SIZE];
using my_type = A<SIZE>;
A() : b{} {} // (1) no params
A(const_buffer_t) : b{} {} // (2) copy contents of given buffer
A(const char * const) : b{} {} // (3) copy as many items as they fit into the size
explicit A(const my_type &) : b{} {} // (4) copy constructor
// (5) copy as many items as …Run Code Online (Sandbox Code Playgroud)