>>I know I can create a pointer array using the new keyword and can specify the size of the array during runtime. In this >>case, how would I resize the array to add a new record or to delete an old one?
In C++ the preferred method for dynamic array is std::vector.
You should use std::vector and then add to the vector as you get objects to put into that vector.
You can access a vector like you would a C style array.
std::vector vInt; vInt.push_back(123); vInt.push_back(456);
cout << vInt[0] << endl; cout << vInt[1] << endl;
A vector will clean up the memory automatically, so you don't have to worry about calling new or delete.
Comment from Axter Date: 07/12/2005 11:14AM PDT Comment
To get the size of your vector, call the size() method
cout << "Qty items in array = " << vInt.size() << endl;
Comment from Axter Date: 07/12/2005 11:17AM PDT Comment
To create an array using a pointer, you use the following method: int Qty = 99; int *pArrayInt = new int[Qty]; Then you must make sure to use delete[] to clean up above variable: delete [] pArrayInt; There is not easy method to reallocate memory created via new[] operator. That's why it's better to use a vector instead, which you can easily increase or decrease it's size. Comment from Esulin Date: 07/12/2005 12:02PM PDT Author Comment Ok... The following is my directory.h header file. -------------------------------------------------------------------------------- #ifndef _directory_H #define _directory_H using namespace::std; class directory { private: std::vector dir; public: directory(); directory(employee); ~directory(); void addEmployee(employee); void delEmployee(string); int countEmployees(); void displayDir(); void sortDir(); int searchDir(); }; #endif -------------------------------------------------------------------------------- I got two questiosn... 1) I get this error "using-declaration for non-member at class scope" when I try to use the std::vector. What am I missing. 2) I have a class called employee that these functions have to deal with. How do I link the employee class to this class so that employee is recognised as a data type? - Esulin Assisted Answer from efn Date: 07/12/2005 07:46PM PDT Grade: A Assisted Answer 1) using namespace::std; This says you want to use the name "std" in the namespace named "namespace". You probably want to use all the names in the "std" namespace. The statement for that is: using namespace std; (No colons.) 2) Put the declaration of the employee class in a file named "employee.h". In the directory.h file, include the line: #include "employee.h" Put this line somewhere before the file tries to do anything with the employee class. Assisted Answer from balder Date: 07/13/2005 03:17AM PDT Grade: A Assisted Answer >1) I get this error "using-declaration for non-member at class scope" when I try to use the std::vector. What am I missing. you are missing #include Comment from Esulin Date: 07/13/2005 08:18AM PDT Author Comment great answer... all of them. Many thanks. Esulin