Mail Archives: djgpp/1997/10/28/14:46:42

From: Arbuckle Kit <djarb AT IDT DOT NET>
Newsgroups: comp.os.msdos.djgpp
Subject: Help w/String class and char*
Date: 28 Oct 1997 14:28:38 GMT
Organization: IDT Internet Services
Lines: 75
Message-ID: <634sqm$>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I have written a String class (reinventing the wheel can be fun) that
overloads various operators as follows. When I try to use them, the
compiler throws up wrrnings along the lines of 'operator == will use
temporary' and 'initializing non const String& with rvalue'. I would
greatly appreciate it if someone would tell me either what's wrong with my
code or, if nothing, how to make the compiler shut up about it(there
doesn't seem to be a switch for either wrning in the docs).

Please reply via email. Thanks.

** String
** A text string
** Copyright(c) Daniel Arbuckle, 1997.
** All rights reserved.


#include <string.h>   //standard C has very good string operations

class String
//This class make string handling much easier than it is with char arrays.
//I am not using the C++ standard library because I don't trust the GNU
//implementation yet.
  char* chars;
  int length; //the length of the string
  int size;   //the size of the array
  void grow();

  String(char str);
  String(char const * str);
  String(char const * str, int end);
  String(String& str);

  String subString(int len, int begin = 0);
  int find(String& sub);

  char* str();  //returns a pointer to the buffer, handle with care!
                //Safer not to use except immediatly after the call to
                //because the buffer may be moved.

  int strlen();   //the length of the char string returned by str()
  int bufsize();  //the length of the buffer returned by str()

  int hash();     //returns a hash of the string

  void append(char other);
  void append(char const * other);
  void append(String& other);

  void insert(char other, int where = 0);
  void insert(char const * other, int where = 0);
  void insert(String& other, int where = 0);

  void remove(int where, int count = 1);

  String operator + (char other);
  String operator + (char const * other);
  String operator + (String& other);
  String& operator = (char other);
  String& operator = (char const * other);
  String& operator = (String& other);
  friend bool operator == (String& a, String& b);


- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019