Hey I'm used to developing in C and I would like to use C++ in a project. Can anyone give me an example of how I would translate this C-style code into C++ code. I know it should compile in a c++ complier but I'm talking using c++ techniques(I.e. classes, RAII)
typedef struct Solution Solution;
struct Solution {
double x[30];
int itt_found;
double value;
};
Solution *NewSolution() {
Solution *S = (Solution *)malloc(sizeof(Solution));
for (int i=0;<=30;i++) {
S->x[i] = 0;
}
S->itt_found = -1;
return S;
}
void FreeSolution(Solution *S) {
if (S != NULL) free(S);
}
int main() {
Solution *S = NewSolution();
S->value = Evaluate(S->x);// Evaluate is another function that returns a double
S->itt_found = 0;
FreeSolution(S);
return EXIT_SUCCESS;
}
Ideally I would like to be able to so something like this in main, but I'm not sure exactly how to create the class, i've read a lot of stuff but incorporating it all together correctly seems a little hard atm.
Solution S(30);//constructor that takes as an argument the size of the double array
S.Evaluate();//a method that would run eval on S.x[] and store result in S.value
cout << S.value << endl;
Ask if you need more info, thanks.
Edit: changed eval to Evaluate since i think eval is a reserved word, or at least confusing. In my actual code I have an array of function pointers which i was using to evaluate the X array and store the result in value. I thought including them would just cause unnecessary bulk and obscure my question.