Vector of Classes?

For my class I need to make an appointment book using classes, and there isn't a set amount of appointments that are supposed to be added, so it needs to be dynamic. I'm trying to figure out how to do this, but I can't figure out how to dynamically make an array of classes so that one can always be added later if the user decides. I know how to if it was just a number and I was using vector.push_back() but never done it with classes.

How can I approach this?

Thanks,
- Kevin
Pretty much you just replace the ints (or whatever) with your class type really.
Oh, easy enough. I'll try that later. Thanks.
First you need to better understand terms of programing. You put in vector not a class, but object of some class type. Class is a description of object. Type int you can also call an object. As it have it's value and methods. So it is the same if you put int or other objects to vector.
Are you sure you don't have that backwards (From what I'm understanding it?) Class is the structure you set up, object is an instance of a structure. What I put in the "vector<...>" will be the class, not the object. That's at least what doesn't pull any immediate errors when I code it. Off to trying it deeper.
Okay, new problem. So I have a class, with nested classes inside. It's an appointment class, that has a private description with a function to set that, and then I have Date and Time classes nested inside of that.

I made a vector of each:
vector<appointment> appVect;
vector<appointment::appointmentDate> dateVect;
vector<appointment::appointmentTime> timeVect;

Now how do I call the functions for each of those to be able to pass those functions the value I want? Lets say user gives command to make a new Appointment. I need it to leave any existing appointments intact (assuming user has entered any), and push_back on the appointment vector, while calling the setDescription I have in there, and then I also later need to call functions in appointmentDate and appointmentTime, while in the same Appointment vector location. If that makes any sense at all.

Are you sure you don't have that backwards (From what I'm understanding it?) Class is the structure you set up, object is an instance of a structure. What I put in the "vector<...>" will be the class, not the object. That's at least what doesn't pull any immediate errors when I code it. Off to trying it deeper.


In "vector<...>" you declare a type of vector but not put a class in it. You put in vector objects of what type like this "vector.push_back()". So vector is an array of objects, but not classes.

If that makes any sense at all.
Not really :S
But I will try to answer. :D

vector<appointment> appVect;
here you create an vector container which holds objects of type appointment. So you first need to put object in container to use class methods.
1
2
3
appointment myobject;
appVect.push_back(myobject);
appVect.[0]->method(23, 65);

Something like this. But don't know right now if you use "->" or "." to use method.
If you put a second object in container you do like this.
1
2
3
appointment myobject2;
appVect.push_back(myobject2);
appVect.[1]->method(76, 54);
Topic archived. No new replies allowed.