我想制作模板类Vector,参数应该是其中动态数组的类型和长度。
template < class Type, int length >
class Vektor
{
public:
int Count;
int CurrentPos;
Type* Beginning = new Type[count];
int LastAtUse=0;
Vektor()
{
Count = length;
}
void PushBack(Type A)
{
Beginning[LastAtUse]=A;
LastAtUse++;
}
void insert(Type A, int position)
{
Beginning[position] = A;
}
};
我尝试在main中测试它并收到错误:
error C2440: 'initializing' : cannot convert from 'iterator_traits<_Iter>::difference_type (__cdecl *)(_InIt,_InIt,const _Ty &)' to 'unsigned int'
你能帮我找到我做错的事吗?
答案 0 :(得分:0)
下面:
Type* Beginning = new Type[count];
^
您有Count
,而不是count
此外,Count
执行时尚未设置new
,您应该将其移至构造函数:
Vektor()
{
Count = length;
Beginning = new Type[Count];
}