Код: Выделить всё
#include <stdafx.h>
#include <conio.h>
using namespace std;
class String {
public:
char* ptr;
String(char* s){
int n = strlen(s);
ptr = new char[n + 1];
strcpy(ptr, s);
}
String(){
ptr=new char[1];
ptr[0]='\0';
}
~String(){
delete [] ptr;
cout << "dectruction " << endl;
}
int operator==(const String &other){
return (strcmp(ptr, other.ptr) == 0);
}
operator char*() {
return ptr;
}
};
int main() {
String a("STRING 1");
String b("STRING 2");
String c;
cout << "The value of a is: " << endl;
cout << a << endl;
cout << "The value of b is: " << endl;
cout << b << endl;
cout << "The value of c is between these brackets<";
cout << c << ">" << endl;
}
Код: Выделить всё
cout << a << endl;
Код: Выделить всё
operator char*() {
return ptr;