从“ int”到“ int *”的无效转换[-fpermissive] [英] invalid conversion from ‘int’ to ‘int*’ [-fpermissive]

查看:426
本文介绍了从“ int”到“ int *”的无效转换[-fpermissive]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

  #include< stdio.h> 
#include< stdlib.h>
#include< iostream>
#include< fstream>
#include< string>
#include< cstdlib>

#define initialSize 50

//公共GCC易于编译的宏

#define n argv [2]

使用命名空间std;

结构点{
int x;
int y;
int z;
}; int最小的int最小(Point * p,int n);

int size = 0,max_size = initialSize;
int * A =新的int [max_size];


int main(int argc,char * argv []){
int test;
Point * p = new Point();
最小(p,测试);

返回0;
}

int最小(点* p,int n){
返回0;
}

据我了解,这对于C ++应该是有效的语法。但是我收到以下编译错误:

  test.cpp:32:20:错误:从'int'到'的无效转换int *'[-fpermissive] 
test.cpp:23:5:错误:初始化'int minimum(Point *,int *)'的参数2 [-fpermissive]

我正在使用以下命令: g ++ -std = c ++ 11 test.cpp



编辑:添加了完整的源代码,而不是摘要。

解决方案

首先:

  #define n argv [2] 

第二个:

  int最小(Point * p,int n); 

第三条:

  int测试; 

第四:

  smallest(p,test); 

我不知道为什么需要这个定义,但是肯定是他引起了这种奇怪的行为。 / p>

I have the following code:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

#define initialSize 50

//Public GCC compiler-friendly macros

#define n argv[2]

using namespace std;

struct Point {
   int x;
   int y;
   int z;
};


int smallest(Point* p, int n);

int size = 0, max_size = initialSize;
int *A = new int[max_size];


int main(int argc, char* argv[]) {
        int test;
        Point* p = new Point();
        smallest(p, test);

    return 0;
}

int smallest(Point *p, int n) {
return 0;
}

From my understanding, this should be valid syntax for C++. However I get the following compiling error:

test.cpp:32:20: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
test.cpp:23:5: error:   initializing argument 2 of ‘int smallest(Point*, int*)’ [-fpermissive]

I am using the command: g++ -std=c++11 test.cpp

EDIT: Added the entire source code instead of snippets. Tried on a different environment but encountered same compiling error.

解决方案

First:

#define n argv[2]

Second:

int smallest(Point* p, int n);

Third:

int test;

Forth:

smallest(p, test);

I don't know why you need that define, but it's definitely him cause such strange behavior.

这篇关于从“ int”到“ int *”的无效转换[-fpermissive]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆