I wrote the following code example and I've had to use -fpermissive to skip the error/warning
#include <iostream>
#include <vector>
using namespace std;
int endOfProgram(){
printf("\n\npress return key to close the program...");
char end[2];
fgets(end, 2, stdin);
return 0;
}
void pointerTest(vector<int> * pointer){
printf("%d\n", pointer);
printf("%#x\n", (unsigned)pointer);
for (auto it = (*pointer).begin(); it < (*pointer).end(); it++)
printf("%d ", *it);
}
int main(){
vector<int> numbers = { 1, 2, 3, 4, 5, 6 };
pointerTest(&numbers);
endOfProgram();
}
error/warning message:
@test:~/workspace $ make
g++ -std=c++11 pointerTest.cc -o pointerTest -fpermissive
pointerTest.cc: In function ‘void pointerTest(std::vector<int>*)’:
pointerTest.cc:13:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<int>*’ [-Wformat=]
printf("%d\n", pointer);
^
pointerTest.cc:14:28: warning: cast from ‘std::vector<int>*’ to ‘unsigned int’ loses precision [-fpermissive]
printf("%#x\n", (unsigned)pointer);
^
obviously these two lines are problematic...
printf("%d\n", pointer);
printf("%#x\n", (unsigned)pointer);
the question: How can I write these lines, in order to avoid using -fpermissive?