1

I am kind of struggling with this Access violation writing location.

I have two classes:

The first one-

class_A
{
private:
    struct Complex
    {
        float time;
        vector<vector<float>> matrix;
    };

    Complex m_tempStruct;
    ConnectivityMatrix* p_ConnMatrix;  //pointer to the second class

    void functionOfClass_A()
    {
        ...
        p_ConnMatrix->functionOfClass_ConnectivityMatrix(m_tempStruct.time, &m_tempStruct.matrix); //sending float and a pointer to vector<vector<float>>
        ...
    }
};

The second one-

class ConnectivityMatrix
{
private:
    struct Complex
    {
        float time;
        vector<vector<float>> matrix;
    };

    Complex m_tempStruct;
    vector<Complex> m_mainVectorConnectivity;

public:
    void functionOfClass_ConnectivityMatrix(float time, vector<vector<float>>* matrix)
    {
        ...
        m_tempStruct.time = time;  //  <--- crashes here
        m_tempStruct.matrix = *matrix;
        m_mainVectorConnectivity.push_back(m_tempStruct);
        ...
    }
};

I can see that time holds a float value and matrix holds two dimension vector of float. but I can't understand why I get this Access violation when I try to assign it on m_tempStruct.time

I will be happy for help on this one.

Thanks.

LogicStuff
  • 19,397
  • 6
  • 54
  • 74
user1673206
  • 1,671
  • 1
  • 23
  • 43
  • 7
    `0xcccccccc` means that you're trying to access an unallocated memory. Check whether you allocated the memory for `p_ConnMatrix`. – LogicStuff Apr 28 '15 at 15:00
  • 2
    Pointer's don't point to classes, they point to objects. I don't see any object of type ConnectivityMatrix being created anywhere in your code. What does p_ConnMatrix point to? Is the pointer initialized to NULL anywhere? Where do you set its value? – Daniel Daranas Apr 28 '15 at 15:08
  • 2
    [Don't use `vector>`](http://www.boost.org/doc/libs/1_42_0/libs/numeric/ublas/doc/matrix.htm). – Quentin Apr 28 '15 at 15:34
  • 3
    0xCCCCCCCC is uninitialized memory [When and why will an OS initialise memory to 0xCD, 0xDD, etc. on malloc/free/new/delete?](http://stackoverflow.com/q/370195/995714) – phuclv Apr 28 '15 at 15:43
  • Hi! thank you for your advice all, I didn't create an object to p_ConnMatrix. so I created one and now it is working well. thanks – user1673206 Apr 28 '15 at 16:25

0 Answers0