首先我知道还有其他问题基本上与这一个相同,但没有一个答案似乎适用于我。我对C++和编程一般都很陌生,所以请尽可能简单地描述一下,谢谢。错误:表达必须有班级类型
所以我试图做一个简单的文本游戏,我有一对夫妇的文件,但是当我尝试使用类从一个方法它会导致错误,说该表达式必须有一个类类型。
这是代码。
的main.cpp
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include "Warrior.h"
using namespace std;
//main function
int main (void)
{
//title screen
cout<< " _____ _ _ _____ \n";
cout<< "| __|_|_____ ___| |___ | __ |___ ___ \n";
cout<< "|__ | | | . | | -_| | -| . | . |\n";
cout<< "|_____|_|_|_|_| _|_|___| |__|__| _|_ |\n";
cout<< " |_| |_| |___|\n";
cout<< "\n\n Enter any # to start \n ";
int start;
anumber:
cin>> start;
if (start < 0 || start > 0)
{
cout<< "\nWelcome to Sam Acker's simple rpg game!\n";
}
Warrior your_warrior(int health , int armor , int weapon);
your_warrior.warrior_name_function; //This is the line with the error
int exit;
cin>> exit;
return 0;
}
Warrior.h
#include <string>
#include <iostream>
class Warrior
{
private:
int health;
int weapon;
int armor;
std::string warrior_name;
public:
int attack();
int warrior_name_function();
Warrior(int health , int weapon , int armor);
~Warrior();
};
Warrior.cpp
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include "Warrior.h"
int Warrior::warrior_name_function()
{
std::cout<< "What would you like to name you warrior?\n";
std::cin>> Warrior::warrior_name;
return 0;
}
int Warrior::attack()
{
return 0;
}
Warrior::Warrior(int health , int armor , int weapon)
{
health == 100;
armor == 1;
weapon == 16;
}
Warrior::~Warrior()
{}
保持简单,水手:我们真的需要在这个代码示例中看到你的开始屏幕吗?保持它的修剪,保持精益,并且游客变得更加敏锐。 –
@KerrekSB很抱歉。有点新在这里。谢谢你的提示。 – katana7070
“anumber:”标签的原因是什么? –