C/C++用了下模板函数,然后就出错了,代码就几行,简化到不能简化的地步了.诸位路过的看一下.全部家都压下了
template<classTT>classAA{public:TT*Data;AA(){Data=newTT[1];}~AA(){deleteData;}};class...
template <class TT>
class AA{
public:
TT *Data;
AA() {Data=new TT[1];}
~AA() {delete Data ;}
};
class BB{
public:
char *str;
BB() {str=new char[20];}
~BB() {delete str ;}
};
int main(int argc, char* argv[])
{
AA<BB> D;
return 0;
} 展开
class AA{
public:
TT *Data;
AA() {Data=new TT[1];}
~AA() {delete Data ;}
};
class BB{
public:
char *str;
BB() {str=new char[20];}
~BB() {delete str ;}
};
int main(int argc, char* argv[])
{
AA<BB> D;
return 0;
} 展开
2个回答
展开全部
#include<iostream>
using namespace std;
template <class TT>
class AA{
public:
TT *Data;
AA() {Data=new TT[1];}
~AA() {delete[] Data ;} //这里错误,删除数组要加[]
};
class BB{
public:
char *str;
BB() {str=new char[20];}
~BB() {delete str ;}
};
int main(int argc, char* argv[])
{
AA<BB> D;
return 0;
}
using namespace std;
template <class TT>
class AA{
public:
TT *Data;
AA() {Data=new TT[1];}
~AA() {delete[] Data ;} //这里错误,删除数组要加[]
};
class BB{
public:
char *str;
BB() {str=new char[20];}
~BB() {delete str ;}
};
int main(int argc, char* argv[])
{
AA<BB> D;
return 0;
}
展开全部
//改成以下这样就OK了
template <class TT>
class AA{
public:
TT *Data;
AA(){
Data=new TT[1];
}
~AA(){
delete [] Data;
}
};
class BB{
public:
char *str;
BB(){
str=new char[20];
}
~BB(){
delete [] str;
}
};
int main(){
AA<BB> D;
return 0;
}
template <class TT>
class AA{
public:
TT *Data;
AA(){
Data=new TT[1];
}
~AA(){
delete [] Data;
}
};
class BB{
public:
char *str;
BB(){
str=new char[20];
}
~BB(){
delete [] str;
}
};
int main(){
AA<BB> D;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询