Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #47469

initiation string not doing as I expected

From Popping mad <rainbow@colition.gov>
Newsgroups comp.lang.c++
Subject initiation string not doing as I expected
Date 2016-12-21 11:16 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <o3doas$1pf$1@reader1.panix.com> (permalink)

Show all headers | View raw


Why is canvas_index not being assigned properly in the initiation list 
unless I do an assignment inside the backets 


/*
 * 
=====================================================================================
 *
 *       Filename:  test.cpp
 *
 *    Description:  Threading Experiment
 *
 *        Version:  1.0
 *        Created:  12/18/2016 12:46:51 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ruben Safir (mn), ruben@mrbrklyn.com
 *        Company:  NYLXS Inc
 *
 * 
=====================================================================================
 */

#include <iostream>
#include <thread>

namespace testing{
	std::thread t[10];
	class PIC
	{
		public:
		PIC():beg{&source[0]}, end{&source[99]} , canvas_index
{canvas}
		{
			
			canvas_index = canvas;
			for(int i = 0; i < 10;i++)
			{
			t[i] = std::thread([this]{ readin(beg); }
);		
			std::cout << i << ": Making a thread"  << 
std::endl; 
			beg += 10;
			}
		};
		
		~PIC()
		{
			std::cout << "In the destructor"  << std::endl;
			for(int i=0; i<10; i++)
			{
				t[i].join();
			std::cout << i << ": Joining a thread"  << 
std::endl; 
			}

		};
		void readin(char * start)
		{
			for( int i = 0; i<10; i++ )
			{
				*canvas_index = *start;
				std::cout << i << ": Copy " << 
reinterpret_cast<char>(*start) << std::endl;
				std::cout << i << ": Copied to 
canvas_index " << reinterpret_cast<char>(*canvas_index) << std::endl;
				canvas_index++;
				start++;
			}

		};

		char * get_canvas()
		{
			return canvas;
		}

		private:
		char * beg;
		char * end;
		char * canvas_index;
		char * canvas = new char[100];
		char source[100] = {
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'
		};
		//int index;
	};
}//end namespace

int main(int argc, char** argv)
{
	testing::PIC fido;
	for(int i = 0; i<100;i++)
	{
		std::cout << i << " Canvas Position " << fido.get_canvas()
[i] << std::endl;
	}

	return 0;
}

Back to comp.lang.c++ | Previous | NextNext in thread | Find similar | Unroll thread


Thread

initiation string not doing as I expected Popping mad <rainbow@colition.gov> - 2016-12-21 11:16 +0000
  Re: initiation string not doing as I expected Paavo Helde <myfirstname@osa.pri.ee> - 2016-12-21 13:50 +0200
    Re: initiation string not doing as I expected "Fred.Zwarts" <F.Zwarts@KVI.nl> - 2016-12-21 13:47 +0100
      Re: initiation string not doing as I expected "Fred.Zwarts" <F.Zwarts@KVI.nl> - 2016-12-21 13:51 +0100
        Re: initiation string not doing as I expected Öö Tiib <ootiib@hot.ee> - 2016-12-21 13:40 -0800
    Re: initiation string not doing as I expected ruben safir <ruben@mrbrklyn.com> - 2016-12-21 14:24 -0500

csiph-web