C++ 类未在C+;中声明错误消息+;

C++ 类未在C+;中声明错误消息+;,c++,class,codeblocks,C++,Class,Codeblocks,所以这段代码是给我运行的,每当我尝试运行它时,我都会收到相同的错误消息。“英语课尚未宣布”。 我对C++很陌生,所以任何事情都有帮助。 目前,我正在使用程序代码块来运行我的代码。当我收到错误消息时,我将其复制并粘贴到我的DevC++编辑器中,并遇到同样的问题 #include <cstdlib> #include <iostream> using namespace std; class Metric { int meters; int centis; public:

所以这段代码是给我运行的,每当我尝试运行它时,我都会收到相同的错误消息。“英语课尚未宣布”。 我对C++很陌生,所以任何事情都有帮助。 目前,我正在使用程序代码块来运行我的代码。当我收到错误消息时,我将其复制并粘贴到我的DevC++编辑器中,并遇到同样的问题

#include <cstdlib>
#include <iostream>

using namespace std;

class Metric {
int meters;
int centis;
public:
       Metric(int m, int cm)
         {
             meters = m; centis = cm;
         }
        Metric( void ) { meters = centis = 0; }

      void ShowMetricData(void)
         {
           cout << "Metric object: meters = " << meters;
           cout << " centimeters = " << centis << "\n\n";
          }


friend class English;
friend bool compare(Metric, English);


};   // code for class English follows this code



class English {
           int  inches, feet;
    public:

 // ‘Default Constructor
         English(void) { feet = 0; inches =  0; }

  // ‘Initializing Constructor
         English(int ft, int in) { feet = ft; inches = in; }

  //  Prototype for a Constructor that converts a
  //    Metric instance  into an English instance
         English(Metric);

  // Prototype for an operator function that converts
  //   an English  instance into a Metric instance
         operator Metric( void );
         friend bool compare(Metric, English);
         };


    /English::operator Metric( )
    // {
    //   Metric MObj;
    //   float MLgth, ELgth;
    //   ELgth = feet * 12 + inches;
    //   MLgth = 2.54 * ELgth;
    //   MObj.meters = (int) ( MLgth / 100.0);
    //   MObj.centis = (int) (MLgth - MObj.meters*100);
    //   cout << "In operator function Metric that converts English ==> Metric: \n\n";
    //   cout << " English object: feet = " << feet
    //              << " and inches = " << inches << "\n\n";
    //   cout << " Metric object: meters  = " << MObj.meters
    //                  << " cms = " << MObj.centis << "\n\n";
    //   return MObj;
    //  }
    //
    //
    // English::English(Metric Met_Obj)
    //{
    //  float MetL, EngL;
    //  MetL = 100.0 * Met_Obj.meters + Met_Obj.centis;
    //  EngL = MetL / 2.54;
    //
    //  feet = (int) ( EngL / 12.0) ;
    //  inches = (int) ( EngL - 12*feet);
    //
    //  cout << "In constructor English(Metric) that converts Metric=>English: \n\n";
    //  cout << " Metric object: meters = " << Met_Obj.meters << " and cms = "<<       Met_Obj.centis << "\n\n";
    //  cout << " feet = " << feet << " inches = " << inches  << "\n\n";
    //}
    //
    //bool compare (Metric mObj, English eObj)
    //   {
    //       float EobjLength;
    //       float MobjLength;
    //
    //       EobjLength = eObj.feet * 12 + eObj.inches;
    //
    //       MobjLength = mObj.meters * 100 + mObj.centis;
    //
    //       if( MobjLength  > EobjLength * 2.54)
    //          return true;
    //       else
    //          return false;
    //}

/


    int main(int argc, char *argv[])
    {
       English EngObj(8, 11);
       Metric MetObj(EngObj);

     //<<<<<<<<<< CODE BLOCK A >>>>>>>>>>>
         if(compare( EngObj,MetObj) )
           {
             cout << "\n\n Metric object is larger\n\n";
             }
          else
             cout << "English object is larger \n\n";
      // <<<<<<<<< END OF CODE BLOCK A >>>>>>>>>>>>>>>
        system("PAUSE");
        return EXIT_SUCCESS;
    }
#包括
#包括
使用名称空间std;
类度量{
整数米;
整数厘米;
公众:
公制(整数米,整数厘米)
{
米=米;厘米=厘米;
}
公制(空){米=厘米=0;}
void ShowMetricData(void)
{
库特
  • 在将班级英语用作米制班级的朋友之前,先声明班级英语
  • Metric MetObj(EngObj);要实现此目的,请在Metric类中声明一个构造函数,该类将英语作为输入;Metric(const Enlish&rhs){}
  • 正确实现compare func,并以正确的顺序发送正确的参数。 As compare func建议输入Metirc,English,而在main中调用compare(English,Metric)。 如果你想这样做,那么就实现一个转换器来让它工作。但是当事情可以干净利落地完成时,你为什么要这样做呢

  • /操作符Metric(),在此处添加双斜杠,然后再次尝试注释注释部分,并在类Metric之前添加
    class English;