Home » Community » Newbie corner » Trouble with reference variable in THISBACK1
Trouble with reference variable in THISBACK1 [message #46783] |
Thu, 04 August 2016 09:17  |
Tom1
Messages: 1302 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
I'm working with U++ 9251 on Windows 10 64-bit using MSC9, MSC10 and MSC15 in 32 bit mode. I just can't figure out what's wrong with my code. It seems the reference variables do not work as parameters in THISBACKx and the actual vector items being referenced do not get updated in the process:
#include <Core/Core.h>
using namespace Upp;
class c_t: Moveable<c_t> {
public:
int x;
int y;
c_t(){
x=99;
y=99;
}
};
class RefTest{
typedef RefTest CLASSNAME;
Vector<c_t> cv;
public:
RefTest(){}
void prepare_c(c_t &c){
c.x=1;
c.y=2;
}
void Run(){
CoWork cw;
for(int i=0;i<1;i++){
c_t &ref=cv.Add();
cw.Do(THISBACK1(prepare_c,ref));
}
cw.Finish();
for(int i=0;i<cv.GetCount();i++){
printf("%d %d\r\n",cv[i].x,cv[i].y);
}
}
};
CONSOLE_APP_MAIN{
RefTest t;
t.Run();
}
It just prints "99 99" whereas I'm expecting "1 2".
Help, anybody?
Best regards,
Tom
|
|
|
|
|
Re: Trouble with reference variable in THISBACK1 [message #46803 is a reply to message #46802] |
Fri, 12 August 2016 09:10  |
Tom1
Messages: 1302 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
Thanks for pointing out that Vector::Add invalidates pointers, although I had already switched to Array for other reasons.
As for MSC15, I'm still waiting for MSC15 / MSC15x64 Protect to emerge...
It seems to me that THISBACK1 does work with pointers but not references. Well, anyway, I guess I'll need to do this in the old way and get prepared for being modern as soon as Protect gets modern too. In any case the new way looks neat.
Thanks,
Tom
|
|
|
Goto Forum:
Current Time: Wed Apr 30 13:18:27 CEST 2025
Total time taken to generate the page: 0.03083 seconds
|