-1

I've made a basic battle system that i want to be accessible at different phases of my story

  int GameStart()
{
    std::unique_ptr<blankCharacter> myCharacter;
    std::unique_ptr<blankEnemy> myEnemy;
    std::unique_ptr<Inventory> myInventory;
    std::unique_ptr<blankEnemy> myBoss;



    string name;
    int choice;
    int Battle;




    cout << " Please enter player name." << endl << endl;
    cin >> name;        
    system("cls");


    cout << "______________________________________________________________________________" << endl;
    cout << "______________________________________________________________________________" << endl;
    cout << "Please select fighting class." << endl << endl;
    cout <<" 1 - Mage, although not the physically strongest, mages offer a healing role" << endl;
    cout <<" 2 - Warrior, the most balanced of all the classes, excelling in durability." << endl;
    cout <<" 3 - Rogue, for players who want to take a more creative approach to battle." << endl;
    cout << "______________________________________________________________________________" << endl;
    cout << "______________________________________________________________________________" << endl;
    cin >> choice;




    switch(choice)
    {
        case 1: //Mage
            myCharacter = std::unique_ptr<blankCharacter>(new Mage(20,40,60,70,100,180,60));
            myInventory = std::unique_ptr<Inventory>(new Inventory(3, 3,3));
            myEnemy = std::unique_ptr<blankEnemy>(new Enemy(150, 60, 150));

        break;

        case 2: //Warrior
            myCharacter = std::unique_ptr<blankCharacter>(new Warrior(40,50,65,100,160,100,60));
            myInventory = std::unique_ptr<Inventory>(new Inventory(3, 3, 3));
            myEnemy = std::unique_ptr<blankEnemy>(new Enemy(150, 60, 150));
            myBoss = std::unique_ptr<blankEnemy>(new Enemy(200, 200, 200));


        break;

        case 3: //Rogue
            myCharacter = std::unique_ptr<blankCharacter>(new Rogue(30,55,70,90,160,100,100));
            myInventory = std::unique_ptr<Inventory>(new Inventory(3, 3, 3));
            myEnemy = std::unique_ptr<blankEnemy>(new Enemy(150,60,150));   


        break;

        default: 
        cout << "Please select a relevant value 1 to 3" << endl << endl;
        break;
    }

After the beginning part of the story you can progress along alternate paths, however i can't seem to get the information to carry over onto them paths although i tried passing them though.

   int SecondPhase(blankCharacter, blankEnemy, string name, Inventory, int Battle, unique_ptr<blankCharacter> myCharacter, unique_ptr<blankEnemy> myEnemy, unique_ptr<Inventory> myInventory,unique_ptr<blankEnemy> myBoss) 

Does anyone know how to solve the problem?

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
MrPurple
  • 105
  • 1
  • 1
  • 7

1 Answers1

0

std::unique_ptr is not copy-constructible, so you cannot pass it by value to any function. Try passing it by reference instead:

int SecondPhase(std::unique_ptr<blankCharacter>& myCharacter)

For a more elaborate answer see here: How do I pass a unique_ptr argument to a constructor or a function?

However I do not really understand your code. For example Enemy seems to be inherited from blankEnemy, while the name suggest that blankEnemy is a special case of an Enemy and thus the inheritance should be the other way around (if at all, because blank sounds like not initialized).

Your inconsistent naming style doesn't help either. Why are some types starting with an uppercase letter and some with a lowercase one?

Community
  • 1
  • 1
  • blankEnemy is the parent class to Enemy, boss, and others i haven't finished yet. I've been told about my naming style. It's only my first year coding, i need to get in the habit of making more meaningful names. Thank you for your help. – MrPurple Jan 06 '14 at 16:58