Over_inc.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 increment operators
  3. #include <iostream.h>
  4. #include <iomanip.h>
  5. #include <string.h>
  6. class String 
  7. {
  8.   public: 
  9.     String String::operator++()
  10.       { strcat(buffer, "X");
  11.         return *this; };
  12.     String String::operator++(int x)
  13.       { strcat(buffer, "X");
  14.         return *this; };
  15.     String(char *string)
  16.       { strcpy(buffer, string);
  17.         length = strlen(buffer); }
  18.     void show_string(void) { cout << buffer << endl; };
  19.   private:
  20.     char buffer[256];
  21.     int length;
  22. };
  23. void main(void)
  24.  {
  25.    String title("Jamsa's C/C++ Programmer's Bible");
  26.    title++;
  27.    title.show_string();
  28.    ++title;
  29.    title.show_string();
  30.  }