下面这个程序问题在哪里呢,昨天看了两个多小时都没成功
//模板类的定义
#include
using namespace std;
template
class ARRAY
{
public:
template
ARRAY(int _size)
{
this->size=_size;
p=new T[this->size];
}
~ARRAY(void)
{
delete this->p;
}
template <typename T>
T* Append(const ARRAY & other)const
{
int i;
T *p1;
p1=new T[this->size+other.size];
for(i=0;i<this->size;i++)
p1[i]=this->p[i];
for(int j=0;j<other.size;i++,j++)
p1[i]=other.p[j];
return p1;
}
template <typename T>
T* operator+(const ARRAY & other)const
{
int i;
T *p1;
p1=new T[this->size+other.size];
for(i=0;i<this->size;i++)
p1[i]=this->p[i];
for(int j=0;j<other.size;i++,j++)
p1[i]=other.p[j];
return p1;
}
template <typename T>
void setarray(void)
{
int i;
for(i=0;i<this->size;i++)
cin>>this->p[i];
}
private:
int size;
T * p;
};
#include
#include"Append.h"
using namespace std;
void Print(double *p,int size)
{
for(int i=0;i
cout
}
//以下为main.cpp
#include
#include"Append.h"
using namespace std;
void Print(double *p,int size)
{
for(int i=0;i
cout
}
int main()
{
double *p;
ARRAY a(5);
ARRAY b(7);
a.setarray(void);
b.setarray(void);
p=a+b;
Print(p,12);
return 0;
}
C:\Users\hp\Desktop\main.cpp(12) : error C2664: '__thiscall ARRAY::ARRAY(const class ARRAY &)' : cannot convert parameter 1 from 'const int' to 'const class ARRAY &'
Reason: cannot convert from 'const int' to 'const class ARRAY'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Users\hp\Desktop\main.cpp(13) : error C2664: '__thiscall ARRAY::ARRAY(const class ARRAY &)' : cannot convert parameter 1 from 'const int' to 'const class ARRAY &'
Reason: cannot convert from 'const int' to 'const class ARRAY'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Users\hp\Desktop\main.cpp(14) : error C2144: syntax error : missing ')' before type 'void'
C:\Users\hp\Desktop\main.cpp(14) : error C2783: 'void thiscall ARRAY::setarray(void)' : could not deduce template argument for 'T'
C:\Users\hp\Desktop\main.cpp(14) : error C2059: syntax error : ')'
C:\Users\hp\Desktop\main.cpp(15) : error C2144: syntax error : missing ')' before type 'void'
C:\Users\hp\Desktop\main.cpp(15) : error C2783: 'void __thiscall ARRAY::setarray(void)' : could not deduce template argument for 'T'
C:\Users\hp\Desktop\main.cpp(15) : error C2059: syntax error : ')'
C:\Users\hp\Desktop\main.cpp(16) : error C2784: 'class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> __cdecl std::operator +(_D,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce template argument for '' from 'class ARRAY
e>'
C:\Users\hp\Desktop\main.cpp(16) : error C2783: ' *thiscall ARRAY::operator +(const class ARRAY &) const' : could not deduce template argument for 'T'
C:\Users\hp\Desktop\main.cpp(16) : error C2676: binary '+' : 'class ARRAY' does not define this operator or a conversion to a type acceptable to the predefined operator
执行 cl.exe 时出错.
13 14行那个构造函数到底错在哪了,我看了参数表列没问题啊