C++ 返回类型';无效';导致错误的函数
我对函数使用了返回类型“void”,但出现了错误-变量或字段“COMBINE”声明为void,其中函数名为COMBINE 出现错误-变量或字段“COMBINE”声明为void,其中函数名为COMBINE 这是我的密码C++ 返回类型';无效';导致错误的函数,c++,C++,我对函数使用了返回类型“void”,但出现了错误-变量或字段“COMBINE”声明为void,其中函数名为COMBINE 出现错误-变量或字段“COMBINE”声明为void,其中函数名为COMBINE 这是我的密码 #include<iostream> using namespace std; void COMBINE(int,int,int); void COMBINE(int *p,int M,int N){ int i,C[M + N],l = 1; fo
#include<iostream>
using namespace std;
void COMBINE(int,int,int);
void COMBINE(int *p,int M,int N){
int i,C[M + N],l = 1;
for(i = 0 ; i < M + N ; i++){
if( ( *(p + i) % 2) == 0){
C[i] = *(p+i);
}
else{
C[M + N - l] = *(p + i);
l++;
}
}
cout<<"The resultant array is ";
for(i = 0 ; i < M + N ; i++){
cout<<C[i]<<" ";
}
}
int main(){
int M,N,i;
cout<<"Enter the size of first array";
cin>>M;
cout<<"Enter the size of second array";
cin>>N;
int A[M],B[N];
int D[M+N];
for(i = 0 ; i < M ; i++){
cout<<"Enter the value of"<<i+1<<"number of first array";
cin>>A[i];
}
for(i = 0 ; i < M ; i++){
cout<<"Enter the value of"<<i+1<<"number of second array";
cin>>B[i];
}
for(i = 0 ; i < M ; i++){
D[i] = A[i];
}
for(i = 0 ; i < N ; i++){
D[i + M] = B[i];
}
void COMBINE(D[0],M,N);
return 0;
}
#包括
使用名称空间std;
无效组合(int,int,int);
无效组合(int*p,int M,int N){
int i,C[M+N],l=1;
对于(i=0;i 联合收割机的正向增量是否有错误
函数是void COMBINE(int*p,int M,int N)
但您已将其声明为void COMBINE(int,int,int);
。因此这里实际上有两个函数,一个没有主体。下面是代码中的问题:
对于合并
,您有两种不同的声明,第一种是
第一个参数是int
,第二个参数是指向int
的指针
您需要在main
中的COMBINE
函数调用中删除键工作void
由于COMBINE
需要指向int
的指针作为其第一个参数,因此需要将地址传递给向量D的第一个元素(&D[0]
),而不是元素本身(D[0]
)
这是全部代码:
#include<iostream>
using namespace std;
void COMBINE(int *,int,int);
void COMBINE(int *p,int M,int N){
int i,C[M + N],l = 1;
for(i = 0 ; i < M + N ; i++){
if( ( *(p + i) % 2) == 0){
C[i] = *(p+i);
}
else{
C[M + N - l] = *(p + i);
l++;
}
}
cout<<"The resultant array is ";
for(i = 0 ; i < M + N ; i++){
cout<<C[i]<<" ";
}
}
int main(){
int M,N,i;
cout<<"Enter the size of first array";
cin>>M;
cout<<"Enter the size of second array";
cin>>N;
int A[M],B[N];
int D[M+N];
for(i = 0 ; i < M ; i++){
cout<<"Enter the value of"<<i+1<<"number of first array";
cin>>A[i];
}
for(i = 0 ; i < M ; i++){
cout<<"Enter the value of"<<i+1<<"number of second array";
cin>>B[i];
}
for(i = 0 ; i < M ; i++){
D[i] = A[i];
}
for(i = 0 ; i < N ; i++){
D[i + M] = B[i];
}
COMBINE(&D[0],M,N);
return 0;
}
#包括
使用名称空间std;
无效组合(int*,int,int);
无效组合(int*p,int M,int N){
int i,C[M+N],l=1;
对于(i=0;i 请告诉我们您正在使用的代码和编译器发出的错误消息…我无法发布我的代码,请在这方面帮助我,只需简单地复制和粘贴即可。我们可以帮助您设置iti的格式我也使用了CTRL+K,但它不接受不知道该怎么做,它说没有正确设置为代码的格式非常感谢,实际上我非常虚弱克林programming@ash请不要为同一个问题发布两个问题,而是等待答案。此外,如果我回答了你的问题,请添加已回答的分数