Overloading operators in C++
P | N


#include <iostream.h>

#include <string.h>

class string {

public:

string(char *); //Constructor

void operator +(char *);

void show_string(void);

private:

char data[256];

};

string::string(char *str)

{strcpy(data,str);}

void string::operator +(char *str)

{strcat(data,str);}

void string::show_string(void)

{cout << data << endl;}

void main(void)

{

string title("CS 2390");

string name("Modeling and Design");

title.show_string();

title + name;

title.show_string();

}


Previous | Next


Last modified at 8/5/97; 12:31:35 PM
Other Links of Interest
College of Computing | EduTech Institute | GVU Center
Mark Guzdial | Papers | CS 2390 Spring '97 Home Page | STABLE | MMC-CaMILE

Slide Master