#include <iostream>
using namespace std;
template <class T>
class Carray{
public:
Carry(int i = 2);//i是数组长度
bool show_array();
T *set_array(int i, int num);
T *enlarge(int oi,int want)//oi为原数组长度,want为需求量
private:
T *p;//任何类型数组的指针
int len;//数组长度
};
template<class T>
Carray<T>::Carry(int i){
p = new T[i]();
len = i;
}
template<class T>
T *Carray<T>::set_array(int len,int num){ /*num为要输入的数量*/
cout<<"请输入一系列相同数据类型的数"<<endl;
int j=0
for(;j < len;j++){
cin>>p[j];
}
if(j < num-1){
p = enlarge(len,num);
for(;j < num;j++)
cin>>p[j];
}
return p;
}
template<class T>
Carray<T>::enlarge(int oi,int want){
T *np = new T[want]();
for(int j = 0;j < oi;j++){
np[j] = p[j];
}
len = want;
return np;
}
template<class T>
bool Carray<T>::show_array(){
for(int j = 0;j < len;j++)
cout<<p[j]<<"\t";
cout<<endl;
return 1;
}
int main(){
Carray<int> a1();
Carray<char>a2(5)
return 1;
}
C++类模版数组编译时显示不存在相应构造函数,可我有啊
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
7条回答 默认 最新
- threenewbee 2015-06-02 02:11关注
一共4个错误。
两个地方缺少分号
carray写成了carry
还有一个没有返回值本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog