Is this c++ native code?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Is this c++ native code?

  1. #1
    Join Date
    Jul 2017
    Posts
    6

    Is this c++ native code?

    I have a code snippet in my code that does not compile and gives me a error
    Code:
    for (SceneNode* childNode : sceneNode.Children())
    		{
    			GetBindPose(*childNode);
    		}
    1>error C2143: syntax error : missing ',' before ':'
    1> error C2143: syntax error : missing ';' before '{'
    1>error C2143: syntax error : missing ',' before ':'
    1>error C2143: syntax error : missing ';' before '{'
    1>error C2143: syntax error : missing ',' before ':'
    1>error C2143: syntax error : missing ';' before '{'
    1>error C2143: syntax error : missing ',' before ':'
    1> error C2143: syntax error : missing ';' before '{'

    Is this native c++?
    And if not, how can I convert it?
    Last edited by terrysworkstation; August 23rd, 2017 at 09:44 AM.

  2. #2
    Join Date
    Feb 2017
    Posts
    147

    Re: Is this c++ native code?

    Quote Originally Posted by terrysworkstation View Post
    Is this native c++?
    And if not, how can I convert it?
    It's a range based for loop and it's native to C++ 11.

    If you have an earlier C++ version you can use an ordinary for loop and iterate using the iterators supplied by sceneNode.Children() instead.

  3. #3
    Join Date
    Jul 2017
    Posts
    6

    Re: Is this c++ native code?

    So far I have

    Code:
    for_each(sceneNode.Children().begin(), sceneNode.Children().end(),[](SceneNode* childNode) {
                    GetBindPoseBottomUp(*childNode);
     });
    I get error
    an enclosing-function local variable cannot be referenced in a lambda body unless if it is in capture list
    Am I right so far?
    Last edited by 2kaud; August 23rd, 2017 at 10:38 AM. Reason: Added code tags

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,711

    Re: Is this c++ native code?

    If you can't use range-based for loop, why not something like (as per c++98) - assuming that GetBindPose() takes this type as parameter.

    Code:
    for (auto childnode = sceneNode.Children().begin(); childnode != sceneNode.Children().end(); ++childnode)
         GetBindPose(*childNode);
    Note that if you can use lambda expressions, then you should be able to use range-based for loops as they were both introduced in c++11. What compiler are you using?
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.3.4)

  5. #5
    Join Date
    Jul 2017
    Posts
    6

    Re: Is this c++ native code?

    Using Visual c++ 2010 express. My errors went away, thx.
    Last edited by terrysworkstation; August 23rd, 2017 at 10:48 AM.

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,711

    Re: Is this c++ native code?

    VS2010 isn't c++11 compliant - and is well out of date. Have you considered upgrading to VS2017 Community Edition - which is free?

    See https://www.visualstudio.com/downloads/
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.3.4)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)