Error in compiling c++ program in Visual Studio 2010

424 views Asked by At

I can't get my following c++ program compiled in Visual Studio 2010. I already have a working build of the same code so I know the code is correct. But I have no idea with what or how it was compiled.

So I would appreciate if someone could just copy the code and try to compile it in VS 2010.

Code:

http://codepad.org/4VtrVBdK

new:

Ok, I did editing according to the comments below. Now the only problems that seem to have remained are related to calls to the overloaded functions. So how to go about it?

2

There are 2 answers

1
Ben Voigt On

Looks like you're missing using namespace std;

8
John Dibling On

so I know the code is correct

What you "know" is false. The code is wrong in many ways. Here is but one example:

for(unsigned int i=0;i<GPNO;i++)    //SORTING ACCORDING TO FITNESS
    for(unsigned int j=i+1;j<GPNO;j++)
        if((gp[i]->fitness)>(gp[j]->fitness))
        {
            gp[i]->mycopy(tmp);
            gp[j]->mycopy(gp[i]);
            tmp->mycopy(gp[j]);
        }



for(i=1;i<=no;i++)
{
    gp[i]->mycopy(gp[GPNO-i]);
}

In the second for loop, i is undeclared. I suspect the original compiler was VC6, which allowed this.

Another problem is the way you're calling pow. You call it with macros (which are patently evil for this purpose), for instance:

pf[i].frq+=(unsigned int)pow(2,2*PF-1);

And the compiler doesn't know which version of pow you had in mind. Case in point for macros being evil for this purpose. Do this:

pf[i].frq+=(unsigned int)pow(2.0,2*PF-1);

Or better yet, get rid of the macros.

Another example of your code being wrong:

#include "stdlib.h"
#include "conio.h"
#include "math.h"

None of these includes are part of the Standard. If you can get them to compile, its only because your compiler was anticipating your mistake. But it's still a mistake.