【问题标题】:Multilevel Inheritance Error "cout does not name a type"多级继承错误“cout 未命名类型”
【发布时间】:2017-03-16 21:03:36
【问题描述】:

Cout 没有命名类型

伙计们,为什么我在使用“iostream and using namespace std”时仍会收到此错误

这是我的代码

   class DateType: public PatientType{

    cout<<"\nEnter Patient ID\n";
    cin>>Patient_ID;
    cout<<"\nEnter  Patient's Age\n";
    cin>>Age;
    cout<<"\nEnter Patient's Date of Birth";
    cin>>DOB;
};

DateType 类派生自 PatientType 类,PatientType 类派生自 PersonType 类。

cout 在任何地方都可以使用,但在 DateType 类中。

【问题讨论】:

  • 你可能想得到a good book on C++
  • 你想做什么?您希望何时运行这些代码行?即使不使用继承也会出现同样的错误。
  • 我的错,我假设我在函数中编写代码,但那是在课堂上

标签: c++ inheritance


【解决方案1】:

cout&lt;&lt;"\nEnter Patient ID\n"; 是一个语句,需要在函数中。

这个和你的其他语句,在类定义的某个地方浮动。这在语法上无效。

这会使编译器感到困惑,并发出一个有点神秘的错误。

【讨论】:

    【解决方案2】:

    您的代码在任何函数之外,这是不正确的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-25
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 2010-11-08
      • 1970-01-01
      相关资源
      最近更新 更多