Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / wxArray: how to change content of an item?

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. wxArray: how to change content of an item?
#3144
Posted by: 2003-12-30 19:02:01
hi,

how is it possible to change the content of a wxArray- item?

//************prog.h
class ClassA;
WX_DECLARE_OBJARRAY(CClassA, XYArray);

class ClassA
{
  public:
      bool bChanged;
...
}


//*************prog.cpp

...
ClassA itemA=XYArray->Item(i);  // Get an item of the Array:
itemA.bChanged=true;                // and change a value...

**here is the problem, the content of  the item is NOT changed in the Array**

One possibility is to remove the item and to add the changed one. But is there a way to change it dircetly?

thx for any help,
greets mart

Message2. Re: wxArray: how to change content of an item?
#3166
Posted by: upCASE 2004-01-01 23:54:38
Hi!

    ClassA c1, c2;
    c1.bChanged=false;
    c2.bChanged=false;    
    
    XYArray* arr = new XYArray;
    arr->Add(c1);
    arr->Add(c2);
    
    ClassA itemA = arr->Item(0);
    itemA.bChanged=true;
    arr->Item(0).bChanged = true;

While itemA is a new object, the line  arr->Item(0).bChanged = true; uses a reference to the object in the array as an lvalue and stores the correct value.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: wxArray: how to change content of an item?
#3168
Posted by: KaReL 2004-01-02 12:40:54
I don't know if this is going to work but you could try this:

ClassA& itemA = arr->Item(0);

This way you should be using a reference to the array-item... When you change now this itemA, you change the item which is in the arr...

Elementary C++ ;)


If this won't work, blame someone else :p
------------------------
Website: www.KaReLs0ft.be
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2023-2-4  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0