我试图建立一个矢量风格类,并以使用模板还有new,delete运营商我有这样一段代码:
template <class type2> class storage
{
private:
type2 *organs;
public:
int num;
storage(); //constructor
~storage(); //destructor
void operator+(type2 newone);
void operator-(int howmany);
type2 operator[](int place);
};
storage<class type2>:: ~storage()
{
delete[] organs; //~~~~~~~Error number 1~~~~~~~~~~
}
void storage<class type2>:: operator+(type2 newone)
{ // ~~~~~~~~~~~Error number 2~~~~~~~~~~~~~~
organs = new type2[1];
num++;
oragns[num-1] = newone;
}
Run Code Online (Sandbox Code Playgroud)
编译器(Dev C++)在错误号1上写入此错误:
无效使用未定义类型`struct type2'
错误号码2上的此错误:
`newone'的类型不完整
但是,我不明白什么是错的.任何提示?
我试图找出一个向量在已经"创建"一些之后如何添加更多对象,我的意思是:
int *ptr;
ptr = new int;
Run Code Online (Sandbox Code Playgroud)
如何使用它,你可以为该指针添加更多的对象吗?(把它变成一个数组)
谢谢!