C++问题 error C2244
#include"stdafx.h"#include"SeqList.h"template<classT>SeqList<T>::SeqList(Ta[],intn){i...
#include "stdafx.h"
#include "SeqList.h"
template<class T>SeqList<T>::SeqList(T a[],int n)
{
if (n>Maxsize)throw"参数非法";
for (int i=0;i<n;i++)
data[i]=a[i];
length=n;
}
template<class T>void SeqList::Bubblesort()
{
int exchange=length;
while (exchange!=-1)
{
int bound=exchange;
exchange=-1;
for (int j=0;j<bound;j++)
{
if(data[j]>data[j+1])
{
int m=data[j];
data[j]=data[j+1];
data[j+1]=m;
exchange=j;
}
}
}
}
template<class T>void SeqList::Printlist()
{
for (int i=0;i<length;i++)
cout<<data[i]<<endl;
}
错误 1 error C2955: “SeqList”: 使用类 模板 需要 模板 参数列表 f:\project\seqlist\seqlist\solution.cpp 14
错误 2 error C2244: “SeqList<T>::Bubblesort”: 无法将函数定义与现有的声明匹配 f:\project\seqlist\seqlist\solution.cpp 32
错误 3 error C2244: “SeqList<T>::Printlist”: 无法将函数定义与现有的声明匹配 f:\project\seqlist\seqlist\solution.cpp 39 展开
#include "SeqList.h"
template<class T>SeqList<T>::SeqList(T a[],int n)
{
if (n>Maxsize)throw"参数非法";
for (int i=0;i<n;i++)
data[i]=a[i];
length=n;
}
template<class T>void SeqList::Bubblesort()
{
int exchange=length;
while (exchange!=-1)
{
int bound=exchange;
exchange=-1;
for (int j=0;j<bound;j++)
{
if(data[j]>data[j+1])
{
int m=data[j];
data[j]=data[j+1];
data[j+1]=m;
exchange=j;
}
}
}
}
template<class T>void SeqList::Printlist()
{
for (int i=0;i<length;i++)
cout<<data[i]<<endl;
}
错误 1 error C2955: “SeqList”: 使用类 模板 需要 模板 参数列表 f:\project\seqlist\seqlist\solution.cpp 14
错误 2 error C2244: “SeqList<T>::Bubblesort”: 无法将函数定义与现有的声明匹配 f:\project\seqlist\seqlist\solution.cpp 32
错误 3 error C2244: “SeqList<T>::Printlist”: 无法将函数定义与现有的声明匹配 f:\project\seqlist\seqlist\solution.cpp 39 展开
2个回答
展开全部
改好了,自己看吧。主要是字符数组初始化的问题,记住只有在定义字符数组的时候才可以用字符串给字符数组赋值。还有一个拼写错误,我也改过来了
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int number(0);
double number1(0);
double number2(0);
struct Convert
{
char convert_name[100];
double convert_rate;
};
Convert convert[3] = {{{"yuan to dollar"},0.125},{"dollar to pound",2},{"yuan to pound",0.0625}};
cout<<"choose a way to convert money"<<endl<<"1.yuan to dollar"<<endl<<"2.dollar to pound"<<endl<<"3.yuan to pound";
cin>>number;
cout<<"please enter the type that you want to convert";
cin>>number1;
if(number<3&&number>=0)
number2=number1*convert[number-1].convert_rate;
else
cout<<"sorry ,you entered a wrong number";
cout<<number1<<convert[number-1].convert_name<<" is "<<number2;
system("PAUSE");
return EXIT_SUCCESS;
}
还不错,希望你采纳。
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int number(0);
double number1(0);
double number2(0);
struct Convert
{
char convert_name[100];
double convert_rate;
};
Convert convert[3] = {{{"yuan to dollar"},0.125},{"dollar to pound",2},{"yuan to pound",0.0625}};
cout<<"choose a way to convert money"<<endl<<"1.yuan to dollar"<<endl<<"2.dollar to pound"<<endl<<"3.yuan to pound";
cin>>number;
cout<<"please enter the type that you want to convert";
cin>>number1;
if(number<3&&number>=0)
number2=number1*convert[number-1].convert_rate;
else
cout<<"sorry ,you entered a wrong number";
cout<<number1<<convert[number-1].convert_name<<" is "<<number2;
system("PAUSE");
return EXIT_SUCCESS;
}
还不错,希望你采纳。
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
单片机,即单片微控制器,也称为单片微型计算机,是将中央处理器(CPU)、存储器(ROM,RAM)、输入/输出接口和其他功能部件集成在一块 在一个小块的集成电路上,从而实现对整个电路或系统的数字式控制。单片机不是完成某一个逻辑功能的芯片,而是...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
展开全部
函数定义写错了。
把
template<class T>void SeqList::Bubblesort()
template<class T>void SeqList::Printlist()
改成
template<class T>
void SeqList<T>::Bubblesort()
template<class T>
void SeqList<T>::Printlist()
把
template<class T>void SeqList::Bubblesort()
template<class T>void SeqList::Printlist()
改成
template<class T>
void SeqList<T>::Bubblesort()
template<class T>
void SeqList<T>::Printlist()
更多追问追答
追问
还是错的,错误变成4个了
追答
贴SeqList.h代码
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询