+ 1
What does "expected primary expression" mean?
Ive been getting that error a lot and I have no idea what it means. For example: the code below is supposed to print the three integer values in the array onto the screen by using a class. When I run the code it says: "In function int main(); expected primary expression before 'int' " How do I fix it? It would also be greatly appreciated if somebody could explain what the error means. Thanks! #include <iostream> using namespace std; class Class { public: void func(int myArr[3]) { cout << myArr[0] << endl << myArr[1] << endl << myArr[2] << endl; } }; int main() { Class obj; obj.func(int[12, 16, 28]); }
2 Respuestas
+ 2
#include <iostream>
using namespace std;
class Class {
public:
void func(int myArr[3]) {
cout << myArr[0] << endl << myArr[1] << endl << myArr[2] << endl;
}
};
int main() {
Class obj;
int a[3]={12,16,28};
obj.func(a);
return 0;
}
0
you forget to wirte return 0; to return a value to main and you array passing method is wrong first go check out array passing concept