-
September 20th, 2012, 07:49 AM
#1
[RESOLVED] object as data member having error
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 ';'
i dont know y these errors, it runs fine in simple c++ environment
-
September 20th, 2012, 07:52 AM
#2
Re: object as data member having error
Did you #include the header file for CTspGAParams?
-
September 20th, 2012, 08:05 AM
#3
Re: object as data member having error
#include "TspGAParams.h"
yes above file is included in pop header
-
September 20th, 2012, 08:06 AM
#4
Re: object as data member having error
im not getting error i dont know what is meant by these errors
-
September 20th, 2012, 08:16 AM
#5
Re: object as data member having error
Originally Posted by tspga
im not getting error i dont know what is meant by these errors
You realize that doesn't make any sense, right?
-
September 20th, 2012, 08:21 AM
#6
Re: object as data member having error
Originally Posted by tspga
im not getting error i dont know what is meant by these errors
So are you getting errors now?
Also, it is no good if we have to keep asking you what you have included. Please post the entire module you're compiling in code tags (you have made 21 posts, and you haven't learned to use code tags?).
Regards,
Paul McKenzie
-
September 20th, 2012, 08:27 AM
#7
Re: object as data member having error
what u wan me to send there are so many files and so many classes
-
September 20th, 2012, 08:29 AM
#8
Re: object as data member having error
Code:
#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 ¶m);
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);
};
-
September 20th, 2012, 08:30 AM
#9
Re: object as data member having error
Code:
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);
};
-
September 20th, 2012, 08:32 AM
#10
Re: object as data member having error
I have sent both header files cpp files however not sent yet if you want them too i can send but they are lil lenghty
-
September 20th, 2012, 08:34 AM
#11
Re: object as data member having error
class CTspGeneticAlgoDoc : public CDocument
{
protected: // create from serialization only
CTspGeneticAlgoDoc();
DECLARE_DYNCREATE(CTspGeneticAlgoDoc)
// Attributes
public:
CTspGAParams GAparams;
// CBSMatrix <double> mat(citysize,citysize,0);
CBSMatrix <double> mat;
CString FileName;
//CTspGA GAAlgo(mat);
CTspGA GAAlgo;
CDialogParam dlgParam;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTspGeneticAlgoDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CTspGeneticAlgoDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CTspGeneticAlgoDoc)
afx_msg void OnGAParameters();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
this is doc class dialog box takes input and that input is passed to generic class object of GAParams
-
September 20th, 2012, 08:39 AM
#12
Re: object as data member having error
Originally Posted by tspga
I have sent both header files cpp files however not sent yet if you want them too i can send but they are lil lenghty
If those are header files, where are the include guards?
Either:
or
Code:
#ifndef YOURHEADER_H
#define YOURHEADER_H
//code
#endif
I don't see either one in those header files.
Regards,
Paul McKenzie
-
September 20th, 2012, 08:43 AM
#13
Re: object as data member having error
-
September 20th, 2012, 08:44 AM
#14
Re: object as data member having error
i have deleted them in sending you
-
September 20th, 2012, 08:49 AM
#15
Re: object as data member having error
Originally Posted by tspga
what u wan me to send there are so many files and so many classes
You have a compiler error, therefore unless we see what you're compiling, then how can we answer you? I can take your original code and make it compile very easily:
Code:
#include "stdafx.h"
template <typename T>
class CBSVector {};
class CTour {};
class CTspGAParams {};
class CPop
{
CBSVector<CTour> pop;
CBSVector<double> probability;
int popsize;
double TotalFitness;
CTour Elite;
CTspGAParams GAParameters;
};
void foo()
{
CPop x;
}
The code compiles OK. So I took your class you posted, added what you failed to provide to us, and got it to compile with no errors. This is why it is important we see what you really have.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|