English 中文(简体)
st点值:<>:指点器?
原标题:Getting value of std::list<>::iterator to pointer?

怎样才能 i一 st子:一ist一ist,一只物体的价值,供日后使用?

Particle *closestParticle;
for(list<Particle>::iterator p1 = mParticles.begin(); p1 != mParticles.end(); ++p1 )
     {
      // Extra stuff removed
            closestParticle = p1; // fails to compile (edit from comments)
     }
最佳回答

Either

Particle *closestParticle;
f或(list<Particle>::iterat或it=mParticles.begin(); it!=mParticles.end(); ++it)
    {
      // Extra stuff removed
            closestParticle = &*it;
    }

list<Particle>::iterat或closestParticle;
f或(list<Particle>::iterat或it=mParticles.begin(); it!=mParticles.end(); ++it )
    {
      // Extra stuff removed
            closestParticle = it;
    }

inline list<Particle>::iterat或findClosestParticle(list<Particle>& pl)
{
    f或(list<Particle>::iterat或it=pl.begin(); it!=pl.end(); ++it )
        {
          // Extra stuff removed
               return it;
        }
    return pl.end();
}

template< typename It > 
inline It findClosestParticle(It begin, It end)
{
    while(begin != end )
        {
          // Extra stuff removed
               return begin;
          ++begin;
        }
    return end;
}

These are s或ted in increasing personal preference. :)

问题回答

关于<代码>>,唯一使名录失效的办法是erase。 因此,我怀疑你在休息时间的某个时候重新打上了<代码>list.erase(p1)。 您需要复印机,转录p1,然后删除复印件。

EDIT:Oh等,你指的是t compile? 如果有的话,请参看@sbi的答复。 但是,你真的需要以好的方式讲你的问题。 你的汇编错误是什么? 或者,它是否在运行时间失败? 然而,在这种情况下,我认为你指的是汇编错误。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签