C++问题,求大神解答
#include <iostream>
using namespace std;
//获取数组的长度
template <typename T>
int getArrayLenth(T& tArray){
return (sizeof(tArray)/sizeof(tArray[0]));
}
int main(){
int b[10];
for(int index=0;index<getArrayLenth(b);index++){
cin>>b[index];
}
cout<<endl;
void selectSort(int b[]);
selectSort(b);
int w;
cin>>w;
return 0;
}
void selectSort(int &b){
for(int index=0;index<getArrayLenth(b)-1;index++){
for(int index1=index+1;index1<getArrayLenth(b);index1++){
if(b[index]>b[index1]){
int temp=b[index];
b[index]=b[index1];
b[index1]=temp;
}
}
}
for(int index=0;index<getArrayLenth(b);index++){
cout<<b[index];
}
}
问题所在: if(b[index]>b[index1]){
int temp=b[index];
b[index]=b[index1];
b[index1];
}
中b[index]处为什么会出现表达式必须包含指向对象的指针的错误,请问这是什么原因?
为什么我把selectSort函数写成模板函数就不会出现这样的问题
c++新学,望大神能解答我的疑惑
using namespace std;
//获取数组的长度
template <typename T>
int getArrayLenth(T& tArray){
return (sizeof(tArray)/sizeof(tArray[0]));
}
int main(){
int b[10];
for(int index=0;index<getArrayLenth(b);index++){
cin>>b[index];
}
cout<<endl;
void selectSort(int b[]);
selectSort(b);
int w;
cin>>w;
return 0;
}
void selectSort(int &b){
for(int index=0;index<getArrayLenth(b)-1;index++){
for(int index1=index+1;index1<getArrayLenth(b);index1++){
if(b[index]>b[index1]){
int temp=b[index];
b[index]=b[index1];
b[index1]=temp;
}
}
}
for(int index=0;index<getArrayLenth(b);index++){
cout<<b[index];
}
}
问题所在: if(b[index]>b[index1]){
int temp=b[index];
b[index]=b[index1];
b[index1];
}
中b[index]处为什么会出现表达式必须包含指向对象的指针的错误,请问这是什么原因?
为什么我把selectSort函数写成模板函数就不会出现这样的问题
c++新学,望大神能解答我的疑惑
...全文
相关推荐
answer-question.zip_数据结构_Visual_C++_
answer question.dsw"和"重载函数.dsw"可能是两个不同的项目,它们可能涉及到问题解答系统或函数的重载。在C++中,函数重载允许我们用相同的函数名但不同的参数列表来实现不同的功能。
04求整数的和与均值.rar
在C++中,这可能是一个.cpp文件,包含实现该功能的主程序;在C#中,可能是.cs文件,代表一个类或控制台应用程序。对于这个问题,解决的基本步骤可能包括:1.
第43课 最大公约数 《小学生C++趣味编程》PPT 源码 课后题答案等(2021.08.22).rar
**课后题答案**:文件中包含的“动动脑”题目可能是一些与最大公约数相关的实践问题,例如“第43课 最大公约数(完整)02 动动脑 第1题.cpp”等,这些题目可能是对理论知识的应用检验,而对应的解答文件可以帮助学生检查和理解自己的解题思路
《C++程序设计》课后习题解答(第二版)
《C++程序设计》课后习题解答(第二版)是王廷等编著的教材配套资源,由作者个人原创,旨在帮助学习者巩固和深化C++编程技能。
第五章 函数习题参考解答
"C++函数设计习题参考解答"在本章节中,我们将学习如何设计函数来解决各种问题。在C++编程中,函数是非常重要的概念之一,它可以帮助我们将复杂的问题分解成小的、可管理的部分,并且可以重复使用代码。


