第二阶段的本地函数定义非法
''SecondPhase' local function definition illegal
我制作了一个基本的战斗系统,我希望在故事的不同阶段都可以使用。
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;
}
在故事的开始部分之后,您可以沿着替代路径前进,但是尽管我尝试通过它们,但我似乎无法获得信息以传递到它们的路径上。
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)
有谁知道如何解决问题?
>std::unique_ptr
不是可复制构造的,因此您不能按值将其传递给任何函数。尝试通过引用传递它:
int SecondPhase(std::unique_ptr<blankCharacter>& myCharacter)
有关更详细的答案,请参见此处:如何将unique_ptr参数传递给构造函数或函数?
但是我并不真正理解您的代码。例如Enemy
似乎是从blankEnemy
继承而来的,而名称表明blankEnemy
是Enemy
的特例,因此继承应该是相反的(如果有的话,因为空白听起来像没有初始化)。
您不一致的命名风格也无济于事。为什么有些类型以大写字母开头,有些以小写字母开头?
相关文章:
- 不同翻译单元中不可重载的非内联函数定义
- Visual Studio中的函数声明和函数定义问题
- 编写代码时C++出现错误:错误 1 错误 C2601:'circle':本地函数定义是非法的
- 具有enable_if外部类原型的模板类构造函数定义
- 类的前向声明之后的类成员函数定义,在类声明之前
- 为函数定义符号不明确的指针参数
- C++模板专用化 - 无法匹配函数定义
- 错误:在第 6 行'{'标记之前,此处不允许使用函数定义
- 找不到 #define 的函数定义
- 根据类型特征更改函数定义?
- 将抽象基类中的所有纯虚函数定义为 varaidaic 模板
- 命名空间更改函数定义
- "Type&"与C++函数定义中的"Type*"
- C++:为什么允许在另一个函数中声明函数,而不允许在函数定义中声明?
- 如何从 C++ 中的现有模板函数定义新函数
- 私有在函数定义/实现的返回值范围内是什么意思 (c++)?
- 越界成员函数定义是否需要一个完全限定的类名,直到全局范围
- 为什么c++允许成员函数定义中实例的私有成员访问
- Qt基类函数定义
- C++函数定义中参数列表后面额外一对括号的含义