CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2005
    Location
    Akron, Ohio
    Posts
    669

    Crash on vector::back()

    I have a strange problem that I'm wondering if someone can help me with. I have the following bit of code:
    Code:
    ...
    std::string new_text;
    Database::Static_Text_List.push_back(new_text);
    Database::Static_Text_List.back() = "Sample text";
    ...
    This particular code uses a static vector<string> list called Static_Text_List, found in class Database. It is called after the Database constructor returns, (i.e. during a function called afterwards). The code crashes on the third line, complaining about "vector iterator + offset out of range." I've no clue what that means. At the point where it crashes, it says the length of the vector list is 1.

    [Note: Yes, I know I could just push_back the text directly, but I'm experimenting with something.]
    error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.

    Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Crash on vector::back()

    You can compile and run this program to convince yourself that if there is an error, it lies elsewhere:
    Code:
    #include <iostream>
    #include <vector>
    #include <string>
    
    int main()
    {
        auto Static_Text_List = std::vector<std::string>();
        std::string new_text;
        Static_Text_List.push_back(new_text);
        Static_Text_List.back() = "Sample text";
        std::cout << Static_Text_List.back() << std::endl;
    }
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jan 2005
    Location
    Akron, Ohio
    Posts
    669

    Re: Crash on vector::back()

    Yeah. It was previously part of a different project and worked fine. Then I chopped the project into a series of smaller ones, creating individual lib's. The static list landed in a separate lib, so I suspect it has something to do with the static nature and being in an entirely separate compilation unit. I don't use statics much, so now there's no better time to learn the caveats...
    error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.

    Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.

  4. #4
    Join Date
    Jan 2005
    Location
    Akron, Ohio
    Posts
    669

    Re: Crash on vector::back()

    No, that can't be it. I just noticed that this occurs within a function that is inside the same compilation unit. The next possibility is that I'm getting a "LNK4210: .CRT section exists; there may be unhandled static initializers or terminators" linking error. I'll look at it more later.
    error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.

    Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.

  5. #5
    Join Date
    Jan 2005
    Location
    Akron, Ohio
    Posts
    669

    Re: Crash on vector::back()

    So I looked into this an have no idea what to do. Apart from understanding that CRT is a C Run Time library that helps with initializing static variables, I have no idea where to go from here. I created an empty project and assigned an entry point. What is CRT and how do I get this annoying problem to go away??

    Edit: I'm using Visual Studio 2013.
    Last edited by paradoxresolved; July 2nd, 2016 at 05:19 PM.
    error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.

    Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Crash on vector::back()

    Did you try what MSDN recommends?
    There are also some discussions in other Forums:
    http://stackoverflow.com/questions/6...s-warning-mean
    http://stackoverflow.com/questions/2...there-may-be-u
    ...
    Victor Nijegorodov

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured