Hello,
Im trying to define a struct that contains a vector<unsigned char*> :
Code:
struct Q
{
vector<unsigned char*> qu;
};
I create a Q with the following function:
Code:
Q * createQ()
{
Q newQ;
Q* ptr;
ptr = &newQ;
return ptr;
}
And have a function that adds an unsigned char to it:
Code:
void enQ(Q * q, unsigned char b)
{
q->qu.push_back(&b);
}
They compile with no errors, but when I use the enQ() function in the following way:
Code:
int main()
{
Q * ptr1 = createQ();
unsigned char theChar = 'x';
enQ(ptr1, theChar);
cout << "ptr1[0]: " << ptr1->qu[0] << endl;
}
... I get a runtime error and the console needs to be closed. What am I missing here?
Thanks in advance,
J