Problem initializing STL element variables with windows API

I am creating a windows application that uses the stings vector as a member variable. For some reason I can compile but when it tries to get to any of the elements of the vector it fails. the error is 0xC0000005: Access violation reading location 0xcdcdcdd9. in a member function of a vector class.

this is the size () function where it breaks down.

size_type capacity() const
{ // return current length of allocated storage
  return (this->_Myend - this->_Myfirst);
}

      

I am using visual studios 2010.

thanks django

+2


a source to share


3 answers


I've encountered similar things before. The most likely cause is a corrupt heap.



0


a source


The problem is not in the STL code, but in the code.

Since you are not pasting your code, I will show you an example of how you should use 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");

      

+1


a source


in the title.

#include <iostream>
#include <string>
#include <vector>

using namespace std;


class Chat
{
protected:
    vector<string> m_buffers;

public:
    Chat();
    ~Chat();
};

      

in cpp

Chat::Chat(){
    string init = "test";
    m_buffers.push_back(init); //crash
}
Chat::~Chat(){

}

      

sorry for the lack of code .... what va i think (palm of the face)

0


a source







All Articles