Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
240 views
Welcome To Ask or Share your Answers For Others

1 Answer

The code you post compiles correctly.

Try not using pointers:

int smallest(const Point& p, int value)
{
  return 0;
}

int main(void)
{
  int test = 15;
  Point p;
  smallest(p, test);
  return EXIT_SUCCESS;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...