CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Apr 1999
    Posts
    27,449

    Re: object as data member having error

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

  2. #17
    Join Date
    Jul 2012
    Posts
    42

    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.

  3. #18
    Join Date
    Jul 2012
    Posts
    42

    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.
    Last edited by tspga; September 20th, 2012 at 09:49 AM.

  4. #19
    Join Date
    Jul 2012
    Posts
    42

    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 &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]

    [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 &params);
    void IncrIteration();
    bool Continue();
    CTspGAParams GetParameters();

    };

    #endif // !defined(AFX_TSPGASTATUS_H__686F8630_A152_4644_9EDA_AB7AAB74B588__INCLUDED_)
    [/TspGAStatus]

  5. #20
    Join Date
    Jul 2012
    Posts
    42

    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

  6. #21
    Join Date
    Apr 1999
    Posts
    27,449

    Re: object as data member having error

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

  7. #22
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: object as data member having error

    Quote Originally Posted by Paul McKenzie View Post
    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.

  8. #23
    Join Date
    Jul 2012
    Posts
    42

    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.
    Last edited by tspga; September 22nd, 2012 at 05:46 AM.

Page 2 of 2 FirstFirst 12

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured