C ++错误表示未声明类

时间:2017-03-06 10:55:40

标签: c++

我在编译器中练习了我的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:错误:&#39; minion&#39;尚未宣布 21:20:错误:在&#39; {&#39;之前预期不合格的身份证令牌

1 个答案:

答案 0 :(得分:0)

您遇到的问题出在DateTime first = DateTime.Parse("2017-06-03 15:58:45"); DateTime second = DateTime.Parse("2017-06-03 16:05:00"); TimeSpan firstTimeOnly = first.TimeOfDay; TimeSpan secondTimeOnly = second.TimeOfDay; bool firstBeforeSecond = firstTimeOnly < secondTimeOnly; // true bool firstEqualsSecond = firstTimeOnly == secondTimeOnly; // false 班级:

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