Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 19th, 2005, 07:57 AM
Registered User
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default subtraction operator overload

I'm a beginner.
Could anybody help me out with this.
How to make a class strin subtraction operator overload, that if it finds "Bill", then deletes it from the text string.
Thank you in advance.

#include <iostream.h>
#include <string.h>

class strin {
   char *place;
   int length;
   strin (char *text);
   strin ();
   strin (strin &kit);
   ~strin () { delete[] place; }
   int getlen () { return length; }
   strin & operator + (strin &arg);

   strin & operator = (const strin &arg);

   void show() { cout << place << endl; }

main() {
   strin a ("The quick pretty brown cow jumps over Bill"),
   b ("Bill"), c;
   c = a + b;
   strin d(b);

strin :: strin (char *text) {
   length = strlen (text);
   place = new char[length+1];
   strcpy(place, text);

strin :: strin() {
   length = 0;
   place = new char[1];
   *place = '\0';

strin :: strin (strin &kit) {
   length = kit.length;
   place = new char[length+1];
   strcpy(place, kit.place);

strin & strin :: operator + (strin &arg) {
   strin *temp = new strin;
   temp -> length = length + arg.length;
   temp -> place = new char[temp->length+1];
   strcpy (temp->place, place);
   strcat (temp->place, arg.place);
   return *temp;

strin & strin :: operator = (const strin &arg) {
   if (this != &arg) {
      delete [] place;
      length = arg.length;
      place = new char[length+1];
      strcpy (place, arg.place);
   return *this;

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid operator for data type. Operator equals di Pusstiu SQL Server 2000 2 August 10th, 2007 04:51 AM
Subtraction in an Access Query pankaj_daga Access 2 April 13th, 2007 06:49 AM
Unary operator overload and inheritance Jonax C++ Programming 8 February 27th, 2006 08:50 AM
Dates Subtraction akhamis SQL Language 1 December 2nd, 2004 04:38 PM
subtraction collie SQL Server 2000 3 November 26th, 2004 01:03 AM

All times are GMT -4. The time now is 06:13 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.