<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2614788</guid>
        <pubDate>Mon, 07 Jun 2010 21:26:09 +0000</pubDate>
        <title>‘this’ was not captured for this lambda function</title>
        <link>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2614788</link>
        <description><![CDATA[miksayer: спасибо]]></description>
        <author>miksayer</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612574</guid>
        <pubDate>Fri, 04 Jun 2010 13:11:02 +0000</pubDate>
        <title>‘this’ was not captured for this lambda function</title>
        <link>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612574</link>
        <description><![CDATA[Flex Ferrum: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=305375&view=findpost&p=2612562'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>miksayer &#064; <time class="tag-quote__quoted-time" datetime="2010-06-04T13:04:19+00:00">04.06.10, 13:04</time></span><div class='quote '>и, кстати, зачем здесь указывать this в квадратных скобках? т.е. мы говорим компилятору, что мы планируем работать с this в самом выражении? </div></div><br>
В квадратных скобках указывается т. н. &quot;capture-list&quot; - перечень переменных, видимых в контексте определения лямбда-функции, который должен быть доступен в её теле. Ты перечисляешь либо конкретные переменные, либо используешь специальные формы:<br>
[=] - все переменные будут доступны по значению.<br>
[&amp;] - все переменные будут доступны по ссылке.<br>
Если оставляешь пустым, то из контекста определения ничего не будет &quot;захвачено&quot;.]]></description>
        <author>Flex Ferrum</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612562</guid>
        <pubDate>Fri, 04 Jun 2010 13:04:19 +0000</pubDate>
        <title>‘this’ was not captured for this lambda function</title>
        <link>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612562</link>
        <description><![CDATA[miksayer: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=305375&view=findpost&p=2612559'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Flex Ferrum &#064; <time class="tag-quote__quoted-time" datetime="2010-06-04T13:01:11+00:00">04.06.10, 13:01</time></span><div class='quote '>и твой код будет мягким и шелковистым.</div></div><br>
спасибо<br>
хочу еще посоветоваться. Что лучше в этом случае использовать: лямбда-выражение, как сделано выше или определить еще один вариант функции WriteByte, чтобы она могла принимала char и передавать уже ее? <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2010-06-04T13:05:52+00:00">04.06.10, 13:05</time></span></span><br>
и, кстати, зачем здесь указывать this в квадратных скобках? т.е. мы говорим компилятору, что мы планируем работать с this в самом выражении?]]></description>
        <author>miksayer</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612559</guid>
        <pubDate>Fri, 04 Jun 2010 13:01:11 +0000</pubDate>
        <title>‘this’ was not captured for this lambda function</title>
        <link>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612559</link>
        <description><![CDATA[Flex Ferrum: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=305375&view=findpost&p=2612553'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>miksayer &#064; <time class="tag-quote__quoted-time" datetime="2010-06-04T12:59:20+00:00">04.06.10, 12:59</time></span><div class='quote '>void BitOStream::WriteString(std::string str) { for_each(str.begin(), str.end(), [<span class="tag-color tag-color-named" data-value="red" style="color: red">this</span>](char c) { WriteByte&copy;; } ); } </div></div><br>
и твой код будет мягким и шелковистым.]]></description>
        <author>Flex Ferrum</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612553</guid>
        <pubDate>Fri, 04 Jun 2010 12:59:20 +0000</pubDate>
        <title>‘this’ was not captured for this lambda function</title>
        <link>https://forum.sources.ru/index.php?showtopic=305375&amp;view=findpost&amp;p=2612553</link>
        <description><![CDATA[miksayer: Код такой:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">void BitOStream::WriteString(std::string str)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;for_each(str.begin(), str.end(), [](char c)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;WriteByte(c);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
Компилятор(g++ 4.5) выдает:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">BitOStream.cpp: In lambda function:</div><div class="code_line">BitOStream.cpp:45:3: ошибка: ‘this’ was not captured for this lambda function</div><div class="code_line">make: *** [flactrim] Ошибка 1</div></ol></div></div></div></div><br>
WriteByte это приватный метод того же класса:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">void WriteByte(uint8_t byte, unsigned short bitCount = BITSINBYTE);</div></ol></div></div></div></div><br>
Как исправить ошибку?]]></description>
        <author>miksayer</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      </channel>
      </rss>
	