-1

I am working with MFC and I have this class:

class CUnit
{
private:
    CString name;
    CString init;
    CString chp;
    CString rhp;
    CString condition;
public:
    CUnit(void);
    ~CUnit(void);
    void setName( CString str );
    void setInit( CString str );
    void setCHP( CString str );
    void setRHP( CString str );
    void setCond( CString str );
    CString getName() const;
    CString getInit() const;
    CString getCHP() const;
    CString getRHP() const;
    CString getCond() const;    
    bool operator< ( CUnit ) const;
};

CUnit::CUnit(void)
{
}


CUnit::~CUnit(void)
{
}

bool CUnit::operator< ( CUnit unit ) const
{
    return !( this->init < unit.init );
}

void CUnit::setName( CString str )
    {
        name = str;
    }
void CUnit::setInit( CString str )
    {
        init = str;
    }
void CUnit::setCHP( CString str )
    {
        chp = str;
    }
void CUnit::setRHP( CString str )
    {
        rhp = str;
    }
void CUnit::setCond( CString str )
    {
        condition = str;
    }
CString CUnit::getName() const
{
    return name;
}
CString CUnit::getInit() const
{
    return init;
}
CString CUnit::getCHP() const
{
    return chp;
}
CString CUnit::getRHP() const
{
    return rhp;
}
CString CUnit::getCond() const
{
    return condition;
}

I get the values from Editboxes successfuly but when I insert them in a set<CUnit> when I get the CString values back I only get the first letter. I tried with a vector but it's all the same.
I fill the set like so:

vector<CUnit> units;
CUnit unit;
CEdit *edit;
CString str;
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_NAME1));
edit->GetWindowText(str);
unit.setName(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_INIT1));
edit->GetWindowText(str);
unit.setInit(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_CHP1);
edit->GetWindowText(str);
unit.setCHP(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_RHP1));
edit->GetWindowText(str);
unit.setRHP(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_COND1+i));
edit->GetWindowText(str);
unit.setCond(str);
units.push_back(unit);

And I use this to check if everything is ok:

vector<CUnit>::iterator pos = units.begin();
str = *pos->getName();
SetDlgItemText(IDC_NAME2, str );
3
  • 3
    Why don't you post the code where you insert in the set? Commented May 16, 2012 at 7:55
  • Umm, so where's the set<CUint> stuff? Commented May 16, 2012 at 7:56
  • Unrelated to the actual question, but in all the set functions, you should pass a const reference to CString, not a CString value. Thus, you avoid unnecessary copying.
    – MikMik
    Commented May 16, 2012 at 8:06

1 Answer 1

0

you may use as follows:

    str = *(pos->getName());

or

    str = (*pos).getName();

wish help you!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.