Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » CoWork usage question
CoWork usage question [message #51091] Tue, 22 January 2019 14:59 Go to previous message
Tom1
Messages: 642
Registered: March 2007
Contributor
Hi,

As I need more than coffee to solve this out, I decided to put it here Smile

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
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Does anyone have experience with dual booting on a notebook with recovery partition?
Next Topic: The eternal quarrel between Python and C
Goto Forum:
  


Current Time: Sun Sep 22 08:29:25 CEST 2019

Total time taken to generate the page: 0.00730 seconds