>> author = a;
You cannot assign C style strings. You have to allocate memory for author and then use strcpy to copy the string.
>> author = a;
You cannot assign C style strings. You have to allocate memory for author and then use strcpy to copy the string.
You can't assign a pointer to another pointer. You can assign a pointer to a reference or a value but then you wouldn't be able to pass in a pointer. At least I think. Also, in your destructor you're trying to delete author. You can only use keyword delete when you allocate memory with keyword new.
I don't think you should assign author to the reference of "a" though. When your program goes through the destructors you'll most likely get a segmentation fault from trying to access inaccessible memory.Code:char * author; author = new char[x]; //allocating x amount of chars delete [] author;
You can keep what you're doing now and just do this:
Code:int length = strlen(a); author = new char[length + 1]; strcpy(author, a); author[length] = '\0'; //null character, you actually don't need this, more of an FYI
Last edited by warfang; 05-09-2007 at 09:48 PM.
Code:if (toLowerChoice == 'b') { pttt = new ... } else if (toLowerChoice == 'r') { pttt = new ... } // What if neither of the conditions are met...? What will you be returning? return pttt; // could be anything // you could try initializing 'pttt' like so, Holding * pttt = 0; // or you could try... switch (toLowerChoice) { case 'r': { // ... break; } case 'b': { // ... break; } default: // if the user refuses to cooperate { pttt = NULL; // pttt = 0; } }; return pttt; // you could also, place within a do{}while until conditions are met do { cout << "\nEnter B for book or R for recording: " << endl; cin >> holdingChoice; switch(toLowerChoice) { // ... } } while (pttt == NULL); return pttt;
> You can't assign a pointer to another pointer.
Not true.
> You cannot assign C style strings
Oh, but you can.
Nevertheless, it's bad practice, especially in C++. Use string objects.