i have tried hard but dont know wy im getting this error , error comes in line 8

class CPop 
{
CBSVector<CTour> pop;
CBSVector<double> probability;
int popsize;
double TotalFitness;
CTour Elite;
**CTspGAParams GAParameters;**
}

error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'




[POP]// Pop.h: interface for the CPop class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_POP_H__EB3D0F86_2CDB_4B6D_BCD2_D33ECC20E5BA__INCLUDED_)
#define AFX_POP_H__EB3D0F86_2CDB_4B6D_BCD2_D33ECC20E5BA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Tour.h"
#include "TspGAParams.h"







class CPop 
{
CBSVector<CTour> pop;
CBSVector<double> probability;
int popsize;
double TotalFitness;
CTour Elite;
CTspGAParams GAParameters;

public:
CPop();
virtual ~CPop();
void seed();
void RandomInitialize(const CTspGAParams &param);
void initializePop(int citysze,int popsze);
bool isExist(int i,int citysze);
void computePopFitness(CBSMatrix<double>& matrix,int citysze);
void MaxMinFitness(int &minIndex,int &maxIndex);
void MaintainElite(int citysze);
void displaypop();
void computeTotalFitness();
void computeProbabilities();
int selectparent();
void performCrossover(int parent1,int parent2,int offspring1,int offspring2,int ncities,CBSVector<CTour> & newPop);
void SwapMutation(int index,int ncities,CBSVector<CTour> & newPop); //,int nExchanges)
void reproduction(int ncities);


};

#endif // !defined(AFX_POP_H__EB3D0F86_2CDB_4B6D_BCD2_D33ECC20E5BA__INCLUDED_)
[/POP]

[TspGAParams]// TspGAParams.h: interface for the CTspGAParams class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TSPGAPARAMS_H__CA596612_60BC_42A7_94CF_755448048E57__INCLUDED_)
#define AFX_TSPGAPARAMS_H__CA596612_60BC_42A7_94CF_755448048E57__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000




class CTspGAParams 
{
int PopSize;
int n_Cities;
int MaxIeration;
double CrossOverRate;
double MutationRate;

//double LowerFitLimit;
//double UpperFitLimit;

public:
CTspGAParams();
virtual ~CTspGAParams();
void InitializeParam(int popsize, int ncities,int MaxIter, double XoverRate,double MutateRate);//,double UpLimit,double LowLimit)
int GetPopSize();
void SetPopSize(int popsize);
int GetCities();
void SetCities(int ncities);
int GetMaxIeration();
void SetMaxIeration(int MaxIter);
double GetCrossOverRate();
void SetCrossOverRate(double XoverRate);
double GetMutationRate();
void SetMutationRate(double MutateRate);


};

#endif // !defined(AFX_TSPGAPARAMS_H__CA596612_60BC_42A7_94CF_755448048E57__INCLUDED_)
[/TspGAParams]

Recommended Answers

All 6 Replies

Nothing jumps out at me from the code you've posted, but if I've missed something obvious, someone else will surely point it out. Failing that, and because the actual error could be prior to the source line reporting it, could you post the content of tour.h also?

i was tinking the same but i guess tis is not te issue bcz when i try composint tspgaparam object in some other class i get same error on line where i declare object as data member, plz smone figure this out, i dont know what the problem is with this line! either i m mising some header or what .

You must put a semicolon ( ; ) right after the closing parenthesis of your class definition.

What are the ** used for? I'm new to coding so I am unfamiliar with that. Also, maybe in order to complete your class CPop, you need to put a semi-colon after the } on line 9. Sometimes that helps the program understand that there is no actual problem with your code.

I think lines 1..9 are just a cut-down version of the actual code in the header file, which is contained in lines 17..68, and which does terminate with a semicolon. But tspga can perhaps clarify.

bob you are right, it is cut down version, and zvjezdan ** is used to just make line prominent** in post it is not related to c++ syntax and for those who read replies because they are facing similar errors i would like to tell i have resolved my issue and the matter was some missing header files, proper initialization of member variables in constructor of tspgaparam class and just replacing this "CTspGAParams GAParameters" by "CTspGAParams gaParameters", i was able to resolve this matter... this means avoid naming your object variables with capitals or atleast first alphabet must be lower case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.