在标准C++中,我们可以写成:
假设前提是,
我认为这是不可能的,但可能有一些巧妙的方法可以做到!
int myArray[5] = {12, 54, 95, 1, 56};
我想使用模板写同样的内容:
Array<int, 5> myArray = {12, 54, 95, 1, 56};
假设前提是,
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 on a specified item
Type & operator[](const unsigned long p_knIndex);
//! Used to access to a const reference on a specified item
//! @param the item of the item to access
//! @return a const reference on a specified item
const Type & operator[](const unsigned long p_knIndex) const;
private:
//! The array collection
Type m_Array[N];
};
我认为这是不可能的,但可能有一些巧妙的方法可以做到!