[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
Re: object as data member having error
Did you #include the header file for CTspGAParams?
Re: object as data member having error
#include "TspGAParams.h"
yes above file is included in pop header
Re: object as data member having error
im not getting error i dont know what is meant by these errors
Re: object as data member having error
Quote:
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?
Re: object as data member having error
Quote:
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
Re: object as data member having error
what u wan me to send there are so many files and so many classes
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);
};
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);
};
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
Re: object as data member having error
Quote:
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
Re: object as data member having error
Quote:
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
Re: object as data member having error
Re: object as data member having error
i have deleted them in sending you
Re: object as data member having error
Quote:
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
Re: object as data member having error
Quote:
Originally Posted by
tspga
i have deleted them
Why??
You need to understand -- unless you post the actual code you're compiling, we have no idea what you're actually compiling. Leaving out headers, include guards, types, etc. are important, as we don't know if these things you left out are causing the compiler error.
In your first post, you left out the terminating semicolon at the end of the class definition. That is a syntax error -- you don't think that's important??
Regards,
Paul McKenzie
Re: object as data member having error
CTspGAParams GAParameters;
this is the line where i get errors i have composed objects of same class in two other classes also but it always gives me same error, plz tell me how can i resolve this , i have to resolve it urgently plz.
Re: object as data member having error
is this possible that i mail you my project? if it is not possible i will send you all the complete header files with everything all guards headers etc.
Re: object as data member having error
[DIALOG CLASS]#if !defined(AFX_DIALOGPARAM_H__0C7E02C5_D8E6_4248_9292_25525F458CCB__INCLUDED_)
#define AFX_DIALOGPARAM_H__0C7E02C5_D8E6_4248_9292_25525F458CCB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DialogParam.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CDialogParam dialog
class CDialogParam : public CDialog
{
// Construction
public:
CDialogParam(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDialogParam)
enum { IDD = IDD_PARAMETERS };
CString m_CrossOverMethod;
double m_CrossOverRate;
int m_MaxIterations;
CString m_MutationMethod;
double m_MutationRate;
int m_No_Of_Cities;
int m_PopSize;
CString m_SelectionMethod;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDialogParam)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDialogParam)
virtual BOOL OnInitDialog();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DIALOGPARAM_H__0C7E02C5_D8E6_4248_9292_25525F458CCB__INCLUDED_)
[/DIALOG CLASS]
[DOCUMENT]// TspGeneticAlgoDoc.h : interface of the CTspGeneticAlgoDoc class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_TSPGENETICALGODOC_H__92CB7D86_0590_4186_BBAD_1D7407AABE1B__INCLUDED_)
#define AFX_TSPGENETICALGODOC_H__92CB7D86_0590_4186_BBAD_1D7407AABE1B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "TspGAParams.h"
#include "BSMatrix.h"
#include "TspGA.h"
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()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TSPGENETICALGODOC_H__92CB7D86_0590_4186_BBAD_1D7407AABE1B__INCLUDED_)
[/DOCUMENT]
[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 ¶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);
};
#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]
[TspGAStatus]// TspGAStatus.h: interface for the CTspGAStatus class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TSPGASTATUS_H__686F8630_A152_4644_9EDA_AB7AAB74B588__INCLUDED_)
#define AFX_TSPGASTATUS_H__686F8630_A152_4644_9EDA_AB7AAB74B588__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "TspGAParams.h"
//#include "TspGAParams.cpp"
class CTspGAStatus
{
//public:
int CurrentIteration;
CTspGAParams Parameters;
public:
CTspGAStatus();
virtual ~CTspGAStatus();
void Initialize(CTspGAParams ¶ms);
void IncrIteration();
bool Continue();
CTspGAParams GetParameters();
};
#endif // !defined(AFX_TSPGASTATUS_H__686F8630_A152_4644_9EDA_AB7AAB74B588__INCLUDED_)
[/TspGAStatus]
Re: object as data member having error
have sent all the required code can u plz figure out whats te problem bcz i dnt knw what is problem in declaring member like that, i dont think there is some problem but i feel tat there is some header file problem either im adding wrong header file or missing some
Re: object as data member having error
Quote:
Originally Posted by
tspga
plz ... bcz
Please write proper English. Others who do not have English as their first language cannot understand what you're writing.
Second, I already stated that you should use code tags when posting code. Look at when I post code, and look when you post code. Do you see a difference? My code is formatted nicely, while your code is unreadable. Go back and fix your posts so that you use code tags.
Regards,
Paul McKenzie
Re: object as data member having error
Quote:
Originally Posted by
Paul McKenzie
Please write proper English. Others who do not have English as their first language cannot understand what you're writing.
Regards,
Paul McKenzie
And those of us for whom English is a first language just find it really annoying. We're adults here. You're not talking to your 12 year old friends in a chat room.
Re: object as data member having error
for those who are reading these replies because they are facing similar errors, i have resolved my issue what you can do is try naming your composed object variable with lower case letters, check for missing header files and lastly make sure that you have written proper constructor for initializing member variables of composed objects .
and to others i would like to just say thank you to make me learn that proper English should be used and code tags should be used.
regards tspga.