In this structure
1 2 3 4 5 6
|
struct mathcomp
{
long double number;
bool numorsign;
const char* sign;
};
|
there is no space allocated to store the data part of
sign
.
Instead at line 60 of obj.cpp there is this:
datastruct.sign = buffer;
which copies the address of
buffer
to sign.
And what is buffer?
It is a local variable defined at line 53
char buffer[10];
As soon as buffer goes out of scope, it no longer exists. The address stored in
sign
is now pointing to an object which no longer exists, that location in memory could contain
anything.
You could instead of a pointer, use a char buffer (an array of characters) and use strcpy(sign, buffer) or just use a std string.
If the intention that sign should be just a single character, then don't bother with a string, just use a plain char.