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).

2

1 Answer 1

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.