Classasn.cpp
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 1k
Development Platform:

C++ Builder

  1. #include <iostream.h>
  2. #include <string.h>
  3. class BookStuff {
  4.   public:
  5.     BookStuff(char *title, char *publisher, char *author);
  6.     void show_book(void) 
  7. cout << "Book: " << title << " by " <<
  8.         author << " Publisher: " << publisher << endl; 
  9. };
  10.     operator char *();
  11.    
  12.   private:
  13.     char title[64];
  14.     char author[64];
  15.     char publisher[64];
  16. };
  17. BookStuff::BookStuff(char *title, char *publisher, char *author)
  18.  {
  19.    strcpy(BookStuff::title, title);
  20.    strcpy(BookStuff::publisher, publisher);
  21.    strcpy(BookStuff::author, author);
  22.  }
  23. BookStuff::operator char *(void)
  24.  {
  25.    char *ptr = new char[256]; 
  26.    
  27.    return(strcpy(ptr, title)); 
  28.  }
  29. void main(void)
  30.  {
  31.    BookStuff big_book("Jamsa's C/C++ Programmer's Bible", "Jamsa Press", 
  32.    "Jamsa and Klander");
  33.    
  34.    char *title;
  35.    title = big_book;
  36.    cout << "The book's title is " << title << endl;
  37.  }