I am making a Timeline application. A timeline can have a TimelineItem. If an item repeats, I want the TimelineItem to hold a vector of type TimelineItemRepeat where the only difference between the values in TimelineItem and TimelineItemRepeat are the start and end times.
As such, I want to make it that whenever I make an edit to an instance of TimelineItem e.g. tl_item.setLocation("Paris"), all of the TimelineItemRepeat instances that relate to the TimelineItem will also update.
I am trying to achieve this by creating the TimelineItem instance and then passing the memory location of each of TimelineItem's variables to the constructor for TimelineItemRepeat.
Currently, I am declaring the variables and passing it to both of my constructors, however, it isn't working. My code:
driver.cpp
short int type = 0;
string desc = "Lunch with Team";
string loc = "New York Office";
time_t start = time_t(0);
time_t end = time_t(600);
vector<TimelineItemRepeat> repeats;
TimelineItem tl_item(type, desc, loc, start, end);
repeats.push_back(TimelineItemRepeat(type, desc, loc, start, end, tl_item));
tl_item.setLinkedItems(repeats);
std::cout << tl_item.toString() << endl;
std::cout << tl_item.getLinkedItems()[0].toString() << endl;
tl_item.setDescription("Dinner with Team");
std::cout << tl_item.toString() << endl;
std::cout << tl_item.getLinkedItems()[0].toString() << endl;
Outputs
TimelineItem Description Address: 0x7fff5ebcb600
0 Lunch with Team 0 600 1
TimelineItemRepeat Description Address: 0x7fff5ebcb6a0
0 Lunch with Team 0 600
TimelineItem Description Address: 0x7fff5ebcb600
0 Dinner with Team 0 600 1
TimelineItemRepeat Description Address: 0x7fff5ebcb6a0
0 Lunch with Team 0 600
Am I going about this the wrong way?