Store data in class

Hi All,

I have a class that picks up data from the serial port and I receive the amount of switches a LDR measures just 1 and 0.

Now I would like to store this in a class as long the program runs how can I accomplish this with managed variables?

Note the serial class runs every second so when I create open a class that I use now
StoreClass Store

Store.Value = LDR_Value; // LDR_Value is the value from the serial bus

When I do this there always will be a copy of StoreClass be created and that doesn't do the trick.

Please help me out here.

Jorz
If you want to accumulate your data in a container, use std containers. vector would suffices as a good container for your job:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <vector>

using namespace std;

int main()
{
   vector<DataType> dataReceived; //define data container
   
   DataType buffer; //type of your data
   while(recevingFromDevice) //loop that keeps running as long as you're receiving from your device
   {
      buffer = getDataFromDevice(); //buffer what you receive from the device
      dataReceived.push_back(buffer); //add this buffer to the stack of data
   }
   //now dataReceived is an array with all received data
}


Hope that helps!
Last edited on
Topic archived. No new replies allowed.