over_dec.cpp
上传用户:dq031136
上传日期:2022-08-08
资源大小:802k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. // This file will not compile under TCLite because it does not support
  2. // dual-overloaded decrement operators
  3. #include <iostream.h>
  4. #include <iomanip.h>
  5. #include <string.h>
  6. class String 
  7. {
  8.   public:
  9.     String String::operator--()
  10.       { buffer[length-1] = NULL;
  11.         length--;
  12.         return *this; };
  13.     String String::operator--(int x)
  14.       { buffer[length-1] = NULL;
  15.         length--;
  16.         return *this; };
  17.     String(char *string)
  18.       { strcpy(buffer, string);
  19.         length = strlen(buffer); }
  20.     void show_string(void) { cout << buffer << endl; };
  21.   private:
  22.     char buffer[256];
  23.     int length;
  24. };
  25. void main(void)
  26.  {
  27.    String title("Jamsa's C/C++ Programmer's Bible");
  28.    title--;
  29.    title.show_string();
  30.    --title;
  31.    title.show_string();
  32.  }