Reputation: 23
I am creating a windows app that uses a vector of stings as a member variable. For some reason, I can compile but when it tries to get at any of the vectors members is crashes. the error is 0xC0000005: Access violation reading location 0xcdcdcdd9. in the member function of the vector class.
this is the size() function where it breaks.
size_type capacity() const
{ // return current length of allocated storage
return (this->_Myend - this->_Myfirst);
}
I am using visual studios 2010.
thank you Django
Upvotes: 2
Views: 188
Reputation: 12387
I've come across this kind of thing before. Most likely cause is a corrupt heap.
Upvotes: 0
Reputation: 23
in the header.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Chat
{
protected:
vector<string> m_buffers;
public:
Chat();
~Chat();
};
in the cpp
Chat::Chat(){
string init = "test";
m_buffers.push_back(init); //crash
}
Chat::~Chat(){
}
sorry about the lack of code.... what wa I thinking (face palm)
Upvotes: 0
Reputation: 347206
The problem is not with the STL code but with your code.
Since you didn't paste your code I'll show you an example of how you should be using a vector of strings.
std::vector<std::string> v;
v.push_back("hello");
v.push_back("world!");
//Note the above 2 string literals get implicitly converted to std::string
assert(v.size() == 2);
assert(v[0] == "hello");
Upvotes: 1