C 错误说未声明类
C++ error says class not declared
我在编译器中练习我的C ,但我解决了所有错误,但是这个错误。它说我的班级没有宣布。我什至没有声明我的第一堂课。
// Example program
#include <iostream>
#include <string>
using namespace std;
class Enemy{
private:
int attack = 0,
block = 0;
public:
void chargedAttack(){
cout << "Get Ready!";
}
void spinningAttack(){
cout << "How bout this!";
}
};
class minion::Enemy{
public:
int specialAttack(int x){
int attackPower = x;
cout << "Take this you chump! " << attackPower + 6;
}
};
int main()
{
minion chump1;
chump1.spinningAttack();
}
这是错误消息:21:7:错误:尚未声明'Minion'21:20:错误:" {'token
您遇到的问题是在minion
类中:
class minion::Enemy{
public:
int specialAttack(int x)
{
int attackPower = x;
cout << "Take this you chump! " << attackPower + 6;
}
};
为了声明儿童课,必须遵循语法:
class ChildClass : public ParentClass
{
// Declare variable and/or functions
};
您正在混淆语法,以便在同类之外实现函数,并声明新类。您可以在他们的班级之外实现功能:
void AnyClassFunction::AnyClass {
但是,您不能使用相同的语法来声明子类。您应该将minion
类的标头线更改为:
class minion : public Enemy{ // This tells the compiler that the minion class is inherited from the Enemy class
public:
int specialAttack(int x)
{
int attackPower = x;
cout << "Take this you chump! " << attackPower + 6;
}
};
相关文章:
- 在气泡排序程序中未声明错误功能
- 我在范围内未声明的错误类有问题
- 未在此范围内声明错误 'xy'
- 我的代码中有错误,未声明的标识符
- 错误:在 C++ 'std'使用未声明的标识符
- 未声明的标识符错误,但变量定义正确 (?)
- 在此范围内未声明错误"Clreol"
- 错误:在 C++ 目标 c 混合'self'使用未声明的标识符
- 错误: C2065: "QTcpSocket" : 未声明的标识符
- C++:outFile错误:outFile未声明
- "inet_ntoa"未声明错误
- C++成员函数未声明错误时(当它看起来是错误时)
- 代码块 HelloWorld C 示例不起作用:未声明错误"ptrdiff_t"
- 枚举包含在标头中 |未声明错误
- 读取未声明错误消息
- C++随机数猜测游戏-变量未声明错误
- 2D矢量在类中调整大小.在此范围内未声明错误
- 在此范围内未声明错误
- 无法调用 VBO 实现所需的函数...未声明错误
- 未声明错误 Nullptr