0
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <locale>
using namespace std;
class Equation
{
   private:
       double a, b, c, d;

    public:
    double fun[4];

    Equation()
    {}
    Equation(double a, double b, double c, double d)
    {
        fun[0] = a;
        fun[1] = b;
        fun[2] = c;
        fun[3] = d;
    }   
};



int main(int argc, char** argv) 
{

    for (int i = 0; i<5; i++)
    {
    Equation arr[i] = new Equation(1, 2, 3, 4);
    }
    return 0;
}

in this code, I tried to create (for loop) and an array and the type of it Equation and gives it some vales

Equation arr[i] = new Equation(1, 2, 3, 4); 

but when I run the code I faced an error(expression must have a constant value).

1 Answers1

2

You are re-declaring arr[i].

for (int i=0; i<5; i++){
    Equation arr[i] = new Equation(1, 2, 3, 4);
}

Instead use this:

Equation arr[5]; // Array of Equation objects
for (int i=0; i<5; i++){
    arr[i] = Equation(1, 2, 3, 4); // assign different object
}
ichikuma
  • 23
  • 3
Jose Maria
  • 455
  • 2
  • 10