在标准 C++ 中我们可以这样写:
int myArray[5] = {12, 54, 95, 1, 56};
Run Code Online (Sandbox Code Playgroud)
我想用模板写同样的东西:
Array<int, 5> myArray = {12, 54, 95, 1, 56};
Run Code Online (Sandbox Code Playgroud)
假如说
template <class Type, unsigned long N>
class Array
{
public:
//! Default constructor
Array();
//! Destructor
virtual ~Array();
//! Used to get the item count
//! @return the item count
unsigned long getCount() const;
//! Used to access to a reference on a specified item
//! @param the item of the item to access
//! @return a reference …Run Code Online (Sandbox Code Playgroud)