By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

Initialization of pointer to a vector

P: 1
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-
Expand|Select|Wrap|Line Numbers
  1. class hodo {
  2. public :
  3.  int sensorDet;
  4. trigger Trigger;
  5. :::
  6. }
  7.  
Now I have a header called base.h contains
Expand|Select|Wrap|Line Numbers
  1. typedef std::vector<unsigned int> Channel;
  2. :::
  3. class trigger{
  4. Channel* sensorVal=0;
  5. }:::
  6.  
Now I declare
Expand|Select|Wrap|Line Numbers
  1. hodo hd1;
  2. unsigned int mydata = 56;
  3. hd1.Trigger.sensorVal->push_back[mydata];
  4.  
I am getting an error stating "Program received signal SIGSEGV, Segmentation fault.
0x000000000041ad26 in std::vector<unsigned 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_finish != this->_M_impl._M_end_of_storage)..."

Please let me know how can I initialize sensorVal?
Thanks and Regards
Jul 8 '16 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
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
Jul 8 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.