I have a class that when instantiated I build two standard struct members. my instantiation is independent and is in its own memory space every time I build one as is the name member, but the struct's built in the constructor are being given the same memory address every time and thus write over the previous instantiations struct? The pointer nor the struct is static any where so I don't see why this is occurring. If any one can spot my error please point it out.
-------------signal.h--------------
prama once
struct GenParams
{
float a;
float b;
};
class signal {
public:
signal();
~signal();
std::string sigName;
GenParams* mGP; //not static so every instance should have its own mGP I set to private as well but made no difference.
};
--------------------siganl.cpp------------------
#include signal.h
signal::signal()
{
GenParams GP; //every instance should have its own member GP at a unique mem location
// but instead GP is created at the same mem location
mGP = &GP; // mGP points to the same mem location every time the constructor is called
//fill struct with default values
GP.a = 0.0;
GP.b = 5.0;
}
signal::~signal()
{ }
--------------------interface.h--------------------
#include signal.h
class interface
{
public:
interface();
~interface();
std::string interName;
std::vector<signal*> sigList;
interface* iPtr;
unsigned int sigNum;
void newSignal();
--------------------------------interface.cpp----------------------
#include interface.h
interface::interface() : iPtr(this)
{ sigNum = 0;}
interface::~interface()
{
for (auto i : sigList)
delete i;
}
interface::newSignal()
{
signal* s = new signal;
//after this line returns the values are stored correctly in memory of struct
//during this line which does not reference the struct or the signal yet I see the structs
// memory get deallocated and go red as if something is writing to it and the values are gone
std::string newSName = this->interName + "sig" std::to_string(sigNum + 1);
//Here some values go back into the struct but they are bogus vals
s->sigName = newSName;
sigList.push_back(s);
//after adding to the list the sig instance has a name correctly written by the line above
//and a pointer it it but the pointer to the struct member mGP all instances point to the
//same memory location?? I don't understand how this is happening.
sigNum++;
}