Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualKhatharr

Posted 13 January 2013 - 02:40 AM

Ehh... I'm pretty sure I'm doing this right.
 
I just got a new hard drive so I took the opportunity to upgrade to Win7 and VS2010 (since I can get them free through my school).
 
I'm trying to update some code with the C++x00 stuff in VS2010 and I came across this for loop that uses an 'erase' on an iterator. That rules out using for-each, but I noticed that I have the variables declared outside the loop and I want to bring them in. (I had put them outside before because they made the line way too long, but with 'auto' and the zooming feature it's managable now.)
 
Anyway, I tried putting the declaration of both the start and end iterators in the for(), but I got a compile error.
 
Is this thing busted (again)? I've subbed in simple int's and I stil have the same problem:
void VirtualKey::unbind(const Binding& binding) {
  auto iter = m_bindings.begin();
  auto end = m_bindings.end();
  for(int i = 1, int j = 7; iter != end; ++iter) {
    if((iter->device == binding.device) && (iter->diKey == binding.diKey)) {
      iter = m_bindings.erase(iter);
      if(iter == end) {break;}
    }
  }
}
 
I'm getting:
1>ClCompile:
1>  cl_VirtualKey.cpp
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2062: type 'int' unexpected
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2143: syntax error : missing ';' before ')'
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2143: syntax error : missing ';' before ')'
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2143: syntax error : missing ';' before '{'
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(25): error C2043: illegal break
1>
1>Build FAILED.

Edit - Nevermind, I'm an idiot. You have to chain multiple declarations off the same type statement, so it would have to be:
int i = 1, j = 7;

Which should work for the auto's as well in this case.

#1Khatharr

Posted 13 January 2013 - 02:34 AM

Ehh... I'm pretty sure I'm doing this right.
 
I just got a new hard drive so I took the opportunity to upgrade to Win7 and VS2010 (since I can get them free through my school).
 
I'm trying to update some code with the C++x00 stuff in VS2010 and I came across this for loop that uses an 'erase' on an iterator. That rules out using for-each, but I noticed that I have the variables declared outside the loop and I want to bring them in. (I had put them outside before because they made the line way too long, but with 'auto' and the zooming feature it's managable now.)
 
Anyway, I tried putting the declaration of both the start and end iterators in the for(), but I got a compile error.
 
Is this thing busted (again)? I've subbed in simple int's and I stil have the same problem:
void VirtualKey::unbind(const Binding& binding) {
  auto iter = m_bindings.begin();
  auto end = m_bindings.end();
  for(int i = 1, int j = 7; iter != end; ++iter) {
    if((iter->device == binding.device) && (iter->diKey == binding.diKey)) {
      iter = m_bindings.erase(iter);
      if(iter == end) {break;}
    }
  }
}
 
I'm getting:
1>ClCompile:
1>  cl_VirtualKey.cpp
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2062: type 'int' unexpected
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2143: syntax error : missing ';' before ')'
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2143: syntax error : missing ';' before ')'
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(22): error C2143: syntax error : missing ';' before '{'
1>c:\users\khatharr\desktop\khatengine\khatengine\cl_virtualkey.cpp(25): error C2043: illegal break
1>
1>Build FAILED.

PARTNERS