I have something similar to:
#include<vector>
using namespace std;
vector<char> temp;
vector<char> allbytes = GetBytes();
vector<MyClass> outsidecontainer;
for(int i=0; i<allbytes.size(); i++){
//Populate my buffer
if(something){
temp.push_back(allbytes[i]);
}
//temporary buffer now needs to be used to create MyClass object
//and outside container store this MyClass object
else{
MyClass m(temp);
outsidecontainer.push_back(m);
//Empty the temporary buffer ready for next population
temp.clear();
}
}
class MyClass{
public:
MyClass(vector<char> Message);
private:
vector<char> Message;
};
The problem is that come the end, outsidecontainer holds empty MyClass objects. In other words, temp has been emptied due to clear(). However, I didnt think this would affect the value in the outsidecontainer because temp is copied in to MyClass m, which is also copied in to outsidecontainer. They are not storing reference or pointers to objects??
How can I implement the above design, being able to use temp to create MyClass objects and clear it for the next population?
EDIT:
Even though MyClass m has loop-scope, does the object added to outsidercontainer remain after the loop has finished because the value was copied in to the array?
EDIT2:
#include "FIXMessage.h"
FIXMessage::FIXMessage(vector<char> message){
Message = message;
}
FIXMessage::FIXMessage(const FIXMessage& rhs){
}