-
June 30th, 2016, 04:10 PM
#1
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.
-
July 1st, 2016, 12:50 AM
#2
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;
}
-
July 1st, 2016, 03:56 AM
#3
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.
-
July 2nd, 2016, 01:34 PM
#4
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.
-
July 2nd, 2016, 05:14 PM
#5
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.
-
July 12th, 2016, 06:11 AM
#6
Re: Crash on vector::back()
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|