Hello there!
I'm in a middle of my DVD rental project. It's my first bigger thing in c++ and I had my c++ classes long time ago, so I have a few issues and difficulties.
So, I have a class:
and I allocate memory for an array of its objects:Code:class movie{ private: string title; string director; string scenario; int year; string genre; int lenght; string country; string leading_role1; string leading_role2; string leading_role3; string leading_role4; string leading_role5; double price; public: void setMovie(); void deleteMovie(); void getMovie(); int compareMovie(string); };
And here is my first question: how is that dynamic memory? I have SIZE elements in it. SIZE is a number defined earlier or when program asks for it (so maybe 'cause of this 2nd thing it's dynamic?) so when I reach this number program would crash, wouldn't it?Code:movie *ptr_movie; ptr_movie=new movie[SIZE];
Let's assume I have 3 movies in my base, there are available under indexes [0], [1], [2]. And now I want to erase element in the middle. So, 1) how do I remove it? By delete[1] ptr_movie? Intuition says something is wrong, if it's not - what happens with array? 2) When I remove 2nd element, should I shift all elements that stands next to it?



1Likes
LinkBack URL
About LinkBacks



