Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. create_task function in PPL

create_task function in PPL

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiohelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Ramnath
    wrote on last edited by
    #1

    why is the code giving error while compiling?

    task my_task()
    {
    auto s = make_shared(L"First value");
    return create_task([s] {
    wcout << *s << endl;
    *s = L"Second value";
    return *s; // It fails because of this.
    }).then([s] {
    wcout << *s << endl;
    *s = L"Third value";
    return *s;
    });
    }

    UPDATED The error is as follows,

    Quote:

    1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\ppltasks.h(372): error C2338: incorrect parameter type for the callable object in 'then'; consider _ExpectedParameterType or task<_ExpectedParameterType> (see below) 1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\ppltasks.h(402): note: see reference to class template instantiation 'Concurrency::details::_FunctionTypeTraits<_Function,_ReturnType>' being compiled 1> with 1> [ 1> _Function=my_task::, 1> _ReturnType=std::wstring 1> ] 1> c:\vc++\concurrency_program\createtask\source.cpp(41): note: see reference to class template instantiation 'Concurrency::details::_ContinuationTypeTraits,_ReturnType>' being compiled 1> with 1> [ 1> _ReturnType=std::wstring 1> ] 1>c:\vc++\concurrency_program\createtask\source.cpp(41): error C2440: 'return': cannot convert from 'Concurrency::task' to 'Concurrency::task' 1> c:\vc++\concurrency_program\createtask\source.cpp(41): note: Constructor for class 'Concurrency::task' is declared 'explicit'

    I am just trying to understand ppl programing structure. Where as the following code compiles.

    task t1 = create_task([]() {
    wprintf(L"create_task\n");
    return wstring(L"create_task"); // It doesn't throw any error
    });

    Jesus saves

    D D 2 Replies Last reply
    0
    • D Daniel Ramnath

      why is the code giving error while compiling?

      task my_task()
      {
      auto s = make_shared(L"First value");
      return create_task([s] {
      wcout << *s << endl;
      *s = L"Second value";
      return *s; // It fails because of this.
      }).then([s] {
      wcout << *s << endl;
      *s = L"Third value";
      return *s;
      });
      }

      UPDATED The error is as follows,

      Quote:

      1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\ppltasks.h(372): error C2338: incorrect parameter type for the callable object in 'then'; consider _ExpectedParameterType or task<_ExpectedParameterType> (see below) 1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\ppltasks.h(402): note: see reference to class template instantiation 'Concurrency::details::_FunctionTypeTraits<_Function,_ReturnType>' being compiled 1> with 1> [ 1> _Function=my_task::, 1> _ReturnType=std::wstring 1> ] 1> c:\vc++\concurrency_program\createtask\source.cpp(41): note: see reference to class template instantiation 'Concurrency::details::_ContinuationTypeTraits,_ReturnType>' being compiled 1> with 1> [ 1> _ReturnType=std::wstring 1> ] 1>c:\vc++\concurrency_program\createtask\source.cpp(41): error C2440: 'return': cannot convert from 'Concurrency::task' to 'Concurrency::task' 1> c:\vc++\concurrency_program\createtask\source.cpp(41): note: Constructor for class 'Concurrency::task' is declared 'explicit'

      I am just trying to understand ppl programing structure. Where as the following code compiles.

      task t1 = create_task([]() {
      wprintf(L"create_task\n");
      return wstring(L"create_task"); // It doesn't throw any error
      });

      Jesus saves

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Daniel Ramnath wrote:

      why is the code giving error while compiling?

      Should we make an attempt at guessing the error?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      D 1 Reply Last reply
      0
      • D Daniel Ramnath

        why is the code giving error while compiling?

        task my_task()
        {
        auto s = make_shared(L"First value");
        return create_task([s] {
        wcout << *s << endl;
        *s = L"Second value";
        return *s; // It fails because of this.
        }).then([s] {
        wcout << *s << endl;
        *s = L"Third value";
        return *s;
        });
        }

        UPDATED The error is as follows,

        Quote:

        1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\ppltasks.h(372): error C2338: incorrect parameter type for the callable object in 'then'; consider _ExpectedParameterType or task<_ExpectedParameterType> (see below) 1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\ppltasks.h(402): note: see reference to class template instantiation 'Concurrency::details::_FunctionTypeTraits<_Function,_ReturnType>' being compiled 1> with 1> [ 1> _Function=my_task::, 1> _ReturnType=std::wstring 1> ] 1> c:\vc++\concurrency_program\createtask\source.cpp(41): note: see reference to class template instantiation 'Concurrency::details::_ContinuationTypeTraits,_ReturnType>' being compiled 1> with 1> [ 1> _ReturnType=std::wstring 1> ] 1>c:\vc++\concurrency_program\createtask\source.cpp(41): error C2440: 'return': cannot convert from 'Concurrency::task' to 'Concurrency::task' 1> c:\vc++\concurrency_program\createtask\source.cpp(41): note: Constructor for class 'Concurrency::task' is declared 'explicit'

        I am just trying to understand ppl programing structure. Where as the following code compiles.

        task t1 = create_task([]() {
        wprintf(L"create_task\n");
        return wstring(L"create_task"); // It doesn't throw any error
        });

        Jesus saves

        D Offline
        D Offline
        Daniel Ramnath
        wrote on last edited by
        #3

        This issue is solved when 'then' function call is parameterized as follows

        task my_task()
        {
        auto s = make_shared(L"First value");
        return create_task([s] { // 2. Compilers show the error here.
        wcout << *s << endl;
        *s = L"Second value";
        return *s; // 3. The error was due to this.
        }).then([](wstring s) { // 1. Actually the fix is here.
        wcout << s << endl;
        s = L"Third value";
        return s;
        });
        }

        Jesus saves

        1 Reply Last reply
        0
        • D David Crow

          Daniel Ramnath wrote:

          why is the code giving error while compiling?

          Should we make an attempt at guessing the error?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          D Offline
          D Offline
          Daniel Ramnath
          wrote on last edited by
          #4

          Sorry, my description was not elaborate. I updated the error. But I found out the reason and posted it below.

          Jesus saves

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups