Initialization of pointer to a vector

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vegaonline
    New Member
    • Jul 2016
    • 1

    Initialization of pointer to a vector

    It may be silly. However, I am now at loss and can't think. So I request handle to move. I have a class like-
    Code:
    class hodo {
    public :
     int sensorDet;
    trigger Trigger;
    :::
    }
    Now I have a header called base.h contains
    Code:
    typedef std::vector<unsigned int> Channel;
    :::
    class trigger{
    Channel* sensorVal=0;
    }:::
    Now I declare
    Code:
    hodo hd1;
    unsigned int mydata = 56;
    hd1.Trigger.sensorVal->push_back[mydata];
    I am getting an error stating "Program received signal SIGSEGV, Segmentation fault.
    0x000000000041a d26 in std::vector<uns igned int, std::allocator< unsigned int> >::emplace_back <int&> (this=0x0) at /usr/include/c++/4.8/bits/vector.tcc:94
    94 if (this->_M_impl._M_fin ish != this->_M_impl._M_end _of_storage)... "

    Please let me know how can I initialize sensorVal?
    Thanks and Regards
    Last edited by vegaonline; Jul 8 '16, 10:01 AM. Reason: I am providing the error that I see so that people may help me more easily
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I don't see where you created the vector.

    I suggest you create your vector as a singleton. That would guarantee only one vector and would provide access to all your classes through a known access point.

    You might read: https://bytes.com/topic/c/insights/6...erns-singleton

    Comment

    Working...