Thread: stl::list error

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    stl::list error

    I am using the standard template library function list. I have made a list and a iterator but the problem is mainly with the iterator.

    This is the code that is giving the error:

    Code:
    ++textiter;
    I also get a warning:

    Code:
    warning C4251: 'D3dEngine::Engine::textlist' : class 'std::list<_Ty>' needs to have dll-interface to be used by clients of class 'D3dEngine::Engine'
    The error that happens is a standard windows error saying the program had to close.

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    That warning is telling you that unless you add
    Code:
    __declspec(dllexport)
    (I think that's the bit you need) to your declaration, your iterator won't be available for use outside of the library you're building. As for the problem, I'd need to see some code before and after that line to have any chance of knowing why incrementing the iterator is failing (though a quick check of initialization and past-end-of-list conditions would be MY starting point, hint hint).

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Ok were here is were I declared the list and iterator:

    Code:
    std::list<FONT> textlist;
    std::list<FONT>::iterator textiter;
    That is declared in my private part of the class, but that shouldn't matter sence only the class uses it.


    Than here is were I use it inside the class:

    Code:
    for (textiter = textlist.begin(); textiter != textlist.end(); ++textiter)
    {
        //Code here, non yet
    }
    I even tried adding a if statement to see if it was empty, and if it wasn't do that. But I still got the same error.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Make it public and see what happens.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    If you don't have any code in your for loop, how do you know the ++textiter is what's causing the problem? That loop should do nothing (and might even be compiled away, depending on compiler options!), so I'd guess that the error is most likely caused by the first instruction AFTER the loop. Can you supply a little more context? Or are you stepping through with the debugger to see this happen?

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    oh sorry yes I used the visual c++ 2005 express debugger and my own ways. I am 99% sure that the ++iter is causing it, and that is why I am stumped. I even tried the while loop with the iter.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    Is there any way you can post/paste somewhere the full class and/or driver program? I'd still bet against it being in the ++iter (unless VC++2k5 Express has a bug...), but with this level of information, it's almost impossible to help (at least for me - someone smarter than me might be able to).

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Well 5 posts up is all the information you should need, the rest of the class is direct x stuff wich works fine. My guess is it has to do with the dll and using the dll.

    I'm really not sure what to do now, I guess I can make do without or make my own semi list type thing.

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    I still think the issue is NOT in the std::list code, but I could be wrong - does it run w/o error if you comment out the loop?

  10. #10
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    yup.

    if I use a while look and the ++itter is inside the while loop but I comment out the ++iter it works. But if I put it back in it gives the error.

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    so the line
    Code:
    ++textiter
    works inside the body of the while loop, but not in the for() construct? That's just weird.

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    lol sorry let me make my self more clear.

    ++textiter does not work in either place. The purpose of the while loop was to prove ++textiter was causing the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM