lt04.cpp

来自「一、教学目的: 能理解C++中运算符重载的需要性」· C++ 代码 · 共 68 行

CPP
68
字号
int j;
double d;
char str[20];

class Coords
{
   public:
      Coords(double a,double b);
      //...
};

class String
{
   public;
      String(char *);
      //...
};

void f()
{
   try
   {
      //...
      throw 10;
      //...

      throw j;        //j为int型
      //...
      throw d;        //d为double型
      throw "abc";
      //...

      throw str;      //字符串
      //...

      throw Coords(1.0,3.0);
      //...

      throw String("def");
    }

  catch(int k)
  {
  //...
  }

  catch(double x)
  {
  //...
  }

  catch(char * ptr)
  {
  //...
  }

  catch(Coords c)
  {
  //...
  }

  catch(String s)
  {
  //...
  }
  
  cout<<"That is ok.\n";
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?