2017-08-03 119 views
-3

我尝试使用向量惠特指针和模块。 我有这个问题与C++: 在main.cpp中:错误无效类型参数的一元'*'(有'int')与模块

#include<iostream> 
    using namespace std; 
    #include "Funcion1.hpp" 

int main (int argc, char *argv[]) { 
    int vec[20]; 
    int *punteroV = &vec[0]; 
    for(int i = 0;i < 10;i++){ 
     cout<<"Ingrese numero: "; 
     cin>>vec[i]; 
    } 
    cout<<FUN(*punteroV) << endl; 
    return 0; 
} 

和模块中:

#include "Funcion1.hpp" 
#include<iostream> 
using namespace std; 
int FUN(int &punteroV){ 

    int num; 
    for(int i = 0;i<10;i++){ 
     for(int j = 0;j<10;j++){ 
      cout<<"i: "<<(punteroV+ i)<<endl<<"j: "<<(punteroV + j)<<endl; 
      if(*(punteroV + i) > *(punteroV + j)){ 
       num = (punteroV + i); 
      } 
     } 
    } 
    return num; 
} 

和.HPP

#ifndef FUNCION1_H 
#define FUNCION1_H 
int FUN(int&); 
#endif 

编译器产生错误的模块中:

error invalid type argument of unary '*' (have 'int') 

这个错误的含义是什么?

+0

这意味着'punterOv + i'是'int',而不是指针。 –

+0

[错误:一元'\ *'(有'int')]的无效类型参数可能的重复(https://stackoverflow.com/questions/33521200/error-invalid-type-argument-of-unary-have- int) – melpomene

+0

是int'* punteroV =&vec [0];' –

回答

0

在功能FUN你有这样一行:

if(*(punteroV + i) > *(punteroV + j)) 

你正在尝试做的到整数的参考指针运算,然后尊重它像一个int*你不能这样做直接的参考。要做参考数学,你必须首先采取这样的地址:

if(*(&punteroV + i) > *(&punteroV + j)){ 
相关问题