[RESOLVED] object as data member having error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: [RESOLVED] object as data member having error

  1. #1
    Join Date
    Jul 2012
    Posts
    42

    [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

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,090

    Re: object as data member having error

    Did you #include the header file for CTspGAParams?

  3. #3
    Join Date
    Jul 2012
    Posts
    42

    Re: object as data member having error

    #include "TspGAParams.h"
    yes above file is included in pop header

  4. #4
    Join Date
    Jul 2012
    Posts
    42

    Re: object as data member having error

    im not getting error i dont know what is meant by these errors

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,090

    Re: object as data member having error

    Quote Originally Posted by tspga View Post
    im not getting error i dont know what is meant by these errors
    You realize that doesn't make any sense, right?

  6. #6
    Join Date
    Apr 1999
    Posts
    27,427

    Re: object as data member having error

    Quote Originally Posted by tspga View Post
    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

  7. #7
    Join Date
    Jul 2012
    Posts
    42

    Re: object as data member having error

    what u wan me to send there are so many files and so many classes

  8. #8
    Join Date
    Jul 2012
    Posts
    42

    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 &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);
    
    
    };

  9. #9
    Join Date
    Jul 2012
    Posts
    42

    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);
    
    
    };

  10. #10
    Join Date
    Jul 2012
    Posts
    42

    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

  11. #11
    Join Date
    Jul 2012
    Posts
    42

    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

  12. #12
    Join Date
    Apr 1999
    Posts
    27,427

    Re: object as data member having error

    Quote Originally Posted by tspga View Post
    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:
    Code:
    #pragma once
    or
    Code:
    #ifndef YOURHEADER_H
    #define YOURHEADER_H
    //code
    #endif
    I don't see either one in those header files.

    Regards,

    Paul McKenzie

  13. #13
    Join Date
    Jul 2012
    Posts
    42

    Re: object as data member having error

    i have deleted them

  14. #14
    Join Date
    Jul 2012
    Posts
    42

    Re: object as data member having error

    i have deleted them in sending you

  15. #15
    Join Date
    Apr 1999
    Posts
    27,427

    Re: object as data member having error

    Quote Originally Posted by tspga View Post
    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

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center