What does "expected primary expression" mean? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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]); }

15th Jun 2016, 8:47 PM
LaserVision
2 Answers
+ 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; }
16th Jun 2016, 11:09 AM
DJ Shiva & DJ Baba Shiv-Shekhar
DJ Shiva & DJ Baba Shiv-Shekhar - avatar
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
16th Jun 2016, 11:12 AM
DJ Shiva & DJ Baba Shiv-Shekhar
DJ Shiva & DJ Baba Shiv-Shekhar - avatar