-7

I am trying to write a program that takes a string and an integer in a class object. The program will then sort the class objects, in an array of objects, by the integer, allowing me to then display the names. Unfortunately, when I try to build the array, I have an error on my assignment operator.

My questions are: Do I need to overload the = operator, and if so, how (somehow I've never figured out how to overload operators)? If not, where am I going wrong?

Here is the code:

    void InitiativeList::makeList(size_type physicalSize, size_type logicalSize)
    {
        string sNewActor;
        int iNewOrder;
        for (size_t index = 0; index < physicalSize; index++)
        {
            if (logicalSize == physicalSize)
            {
                grow(physicalSize);
            }
            cout << "Enter character name: ";
            cin >> sNewActor;

            if (sNewActor == "Exit")
            {
                return;
            }

            cout << "Enter initiative roll: ";
            cin >> iNewOrder;
            actorOrder[index] = new Actor(iNewOrder, sNewActor);
            logicalSize++;
        }
    }

Thank you for your help.

  • 1
    "_but I figure it's better to show everything_" - NO it is not. – Khalil Khalaf Jan 02 '18 at 17:47
  • 2
    Please learn how to create a [**Minimal**, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). And unless you're asking about build errors, then make sure the example actually builds. And *if* you're asking about build errors (which I think you are) then copy (as text) the full and complete build output and paste it into the question body. Please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). – Some programmer dude Jan 02 '18 at 17:51
  • 2
    Possible duplicate of [What are the basic rules and idioms for operator overloading?](https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading) – user0042 Jan 02 '18 at 17:52

1 Answers1

1

You don't need new there, because you have an array of actorData and not actorData pointers, and the error is saying that it can't convert actorData pointer to actorData. So replace this line:

actorOrder[index] = new actorData(iNewOrder, sNewActor);

with this:

actorOrder[index] = actorData(iNewOrder, sNewActor);
mdatsev
  • 3,054
  • 13
  • 28