I need help with my cpp project.
I have a class Item with a variable for ID that should assign a new ID (add one onto the previous value) but every time I call the function it assigns the same value (1)
class Item{
private:
int Unique_ID = 0;
int* ID_pointer = &Unique_ID;
};
void Item::New_Item(){
Item n;
*ID_pointer += 1;
std::cout << "Unique ID code created for this item is: " << Unique_ID << "\n";
}
When I call this function again to add another item and write the info in the text file the ID is 1 for every new item. How can I fix this? I hope this is enough info (this is my first post and I'm new to this) Thanks
EDIT: https://godbolt.org/z/N-DyC_ link to my code if that helps because i feel like im not explaining it well im making a shop management system that writes information to a text file.