Requesting help with my homework problem.

error: conversion from 'std::string*' to non-scalar type 'std::string' requested

The lines with the error are under the comments.
Thanks.

#include <QtCore/QCoreApplication>
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

typedef string* stringPtr;

string* addEntry(string *dynamicArray, int &size, string newEntry);
string* deleteEntry(string *dynamicArray, int &size, string entryToDelete);

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    stringPtr dynamicArray, name;
    int array_size = 5, add_delete;
    dynamicArray = new string[array_size];
    name = new string;

/*
    createDefaultNames(dynamicArray, array_size);
    intro();
    print(dynamicArray, array_size);
    receiveInput(name);
    add_delete = searchArray(dynamicArray, name, array_size);
*/

    if (add_delete == 1)
//error points to line right under
        dynamicArray = addEntry(dynamicArray, array_size, name);
    else //add_delete == 0
//same error to line under this too
        dynamicArray = deleteEntry(dynamicArray, array_size, name);


    print(dynamicArray, array_size);


    delete [] dynamicArray;
    delete name;

    return a.exec();
}


string *addEntry(string *dynamicArray, int &size, string newEntry)
{
    size++;
    stringPtr tempArray;
    tempArray = new stringPtr[size];

    for(int i = 0; i < (size - 1); i++)
    {
        tempArray[i] = dynamicArray[i];
    }
    tempArray[size] = newEntry;

    delete [] dynamicArray;
    dynamicArray = new stringPtr[size];
    for(int i = 0; i < size; i++)
    {
        dynamicArray[i] = tempArray[i];
    }
    return dynamicArray;
}

string* deleteEntry(string *dynamicArray, int &size, string entryToDelete)
{
    size--;
    stringPtr tempArray;
    tempArray = new stringPtr[size];

    for(int i = 0; i < (size - 1); i++)
    {
        tempArray[i] = dynamicArray[i];
    }

    delete [] dynamicArray;
    dynamicArray = new stringPtr[size];

    for(int i = 0; i < size; i++)
    {
        dynamicArray[i] = tempArray[i];
    }
    return dynamicArray;
}

addEntry's third parameter should be a string, according to the declaration of the function, but you're passing it a pointer to a string. Likewise deleteEntry.

addEntry's third parameter should be a string, according to the declaration of the function, but you're passing it a pointer to a string. Likewise deleteEntry.

Thanks, I got it working.

The problem was within the main body function, and the function declaration I didn't change. I forgot to set the name as a pointer, causing the problem.

This question has already been answered. Start a new discussion instead.