Hey, I'm used to developing in C, and I would like to use C ++ in a project. Can someone give me an example of how I will translate this C-style code into C ++ code. I know that it should compile in a C ++ compiler, but I speak using C ++ methods (Ie 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);
Ideally, I would like to be able to do something similar basically, but I'm not sure exactly how to create a class, I read a lot of new things, but including it all together correctly seems a little difficult.
Solution S(30);
Ask if you need more information, thanks.
Edit: changed eval to Evaluate, since I think that eval is a reserved word or at least confusing. In my actual code, I have an array of pointers to functions that I used to evaluate an array of X and store the result in a value. I thought that even they would simply cause extra volume and overshadow my question.
source share