Hello all,
Noob at c++. Trying to make a friends contact function using a struct that creates a 3D array dynamically with pointers. The code for creating the array appears to be correct.......
Code:#include <iostream> #include <string> using namespace std; struct friends_of_mine { // Create struct. string name; int lcontact; int dcontact; }; friends_of_mine contact( int size); // Declare the function. int main () { int menu; cout << "Welcome to the Contact Manager" << "\n"; cout << "Please choose from the following options" << "\n"; cout << "Press 1 - To add contacts" << "\n"; cout << "Press 2 - To display all contacts" << "\n"; cout << "Press 3 - To modify the contacts database" << "\n"; cout << "Press 4 - To quit" << "\n"; cin >> menu; switch ( menu ) // This switch/case is a work in progress. { case 1: cout << "How many contacts would you like to add?"<<"\n"; int size; cin >> size; contact(size); break; } } friends_of_mine contact (int size) { friends_of_mine ***p_p_p_Contact; // Create a pointer to an array of pointers to pointers. p_p_p_Contact = new friends_of_mine**[size]; // Dynamically allocate a new array using friends_of_mine struct //type. for ( int i = 0; i < size; i++) { p_p_p_Contact[i] = new friends_of_mine *[size]; // Now make the array of pointers to pointers, //POINT to a secondary array of pointers. for ( int j = 0; j < size; j++) { p_p_p_Contact[i][j] = new friends_of_mine[size]; // Now make that array of pointers point to an array of //structs with type friends_of_mine. } }
but when it comes to inputting data to the array, the syntax or semantics used with cin appears to be an issue and the compiler halts here -
Code:for ( int i = 0; i < size; i++ ) { cout << "Enter the name of your friend" << "\n"; cin >> p_p_p_Contact[i].name; // Here is where the compiler complains - /*friends_3darray.cpp|64|error: request for member 'name' in '*(p_p_p_Contact + ((unsigned int)(((unsigned int)i) * 4u)))', which is of non-class type 'friends_of_mine**'|*/ for ( int j = 0; j < size; j++ ) { cout << "Enter the date of last contact" << "\n"; cin >> p_p_p_Contact[j].lcontact; for ( int k = 0; k < size; k++ ) { cout << "Enter the days since last contact" << "\n"; cin >> p_p_p_Contact[k].dcontact; } } } }
Any ideas as to what I could be doing wrong?
thank you in advance!
spark*



LinkBack URL
About LinkBacks




