#include<iostream>
#include<stdio.h>
using namespace std;
class Test
{
private:
int array[]={0,2,4,6,8,10,12};//this line is the root cause of the error but why ?
public :
void compute();
};
void Test::compute()
{
int result =0;
for(int i=0;i<7;i++)
{
result += array[i];
}
cout<<result;
}
int main()
{
Test obj;
obj.compute();
return 0;
}
If I replace int array[]
in the above code with array[7]
then the program compiles and runs with warnings.