Home » Community » Coffee corner » CoWork usage question
CoWork usage question [message #51091] |
Tue, 22 January 2019 14:59 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Hi,
As I need more than coffee to solve this out, I decided to put it here
The question is: What am I doing wrong, as the following code does not work as I expect, i.e. multiply the items by two and show the results:
#include <Core/Core.h>
using namespace Upp;
#define ICOUNT 15
class A{
public:
Buffer<int> ib;
A(){
ib.Alloc(ICOUNT,0);
for(int i=0;i<ICOUNT;i++) ib[i]=i+1;
}
void operation(int &x){
x*=2;
}
void operationp(int *x){
*x*=2;
}
void Run(){
Cout() << "ib = ";
for(int i=0;i<ICOUNT;i++) Cout() << ib[i] << ", ";
CoWork co;
for(int i=0;i<ICOUNT;i++){
//co & [&] { operation(ib[i]); }; // Reference variant
co & [&] { operationp(&ib[i]); }; // Pointer variant
}
co.Finish();
Sleep(400);
Cout() << "\n\nib*2 = ";
for(int i=0;i<ICOUNT;i++) Cout() << ib[i] << ", ";
Cout() << "\n\n";
}
};
CONSOLE_APP_MAIN
{
A ac;
ac.Run();
}
Mostly the results are 'exciting' to say the least.
Best regards,
Tom
|
|
|
Goto Forum:
Current Time: Fri Apr 26 10:46:37 CEST 2024
Total time taken to generate the page: 0.03679 seconds
|