dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Variable for a member variable

  1. #1
    Join Date
    Jul 2006
    Posts
    141

    Variable for a member variable

    Hello

    I have 2 combo boxes in the same class that use the same code.
    So I wrote a function for combobox1 and another for combobox2.

    Is it possible to assign a variable for the controls and passing it to the function so that the same code can be used?

    Any help is much appreciated.

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

    Re: Variable for a member variable

    Yes. You can assign a control variable using Class Wizard.

  3. #3
    Join Date
    Jul 2006
    Posts
    141

    Re: Variable for a member variable

    Thanks GCDEF for your clear reply.


    Obviously I do something wrong after that.

    what I am trying to do is:

    CComboBox m_cbtheme;

    cbthemea.SubclassDlgItem(IDC_THEMEA,this);
    cbthemeb.SubclassDlgItem(IDC_THEMEB,this);

    m_cbtheme=cbthemea; //m_cbthemea passed to the function when doing themea
    m_cbtheme=cbthemeb; //m_cbthemeb passed to the function when doing themeb

    So I can use m_cbtheme.AddString(xxx); for A and for B.


    However, the assignment m_cbtheme=cbthemea; results in

    Error C2248: 'CObject:perator =' : cannot access private member declared in class 'CObject' d:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxwin.h


    I know, most likely a stupid way to do it, but couldn't resist to try to find out.

  4. #4
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,716

    Re: Variable for a member variable

    You can not copy classes that are derived from CObject (for the reason given in the error message).

    You should be able to use a pointer instead:

    Code:
    CComboBox * m_cbtheme;
    
    m_cbtheme = &cbthemea;
    and pass the pointer to the function.

  5. #5
    Join Date
    Jul 2006
    Posts
    141

    Resolved Re: Variable for a member variable

    Thanks a lot Philip Nicoletti

    Exactly what I was looking for.

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




On-Demand Webinars (sponsored)