#include <iostream>
using namespace std;

class Blah;

class String {
int len;
char *data;

public:
static int CStringLength( const char* c ) {
int count = 0;
while( *c != '\0' ) {
++c;
++count;
}//while
return count;
}//CStringLength

static char* CStringCopy( char *to, const char* from ) {
//copies from to to.
//from: '\0' terminated c string
//to: will point to a new c string with same content as from

if( to != NULL ) {
delete [] to;
}//if
/*
for( int i=0; i<len; ++i ) {
*(data+i) = *(d+i);
}//for
*(data+len) = '\0';
*/
return NULL;
}//CStringCopy

String() {
len = 0;
data = NULL;
}//default constructor

String( const String& cp ) : len(cp.len) {
data = new char[ len+1 ];
}//copy constructor



String( const char *d ) {
len = String::CStringLength( d );
data = new char[ len+1 ];
for( int i=0; i<len; ++i ) {
*(data+i) = *(d+i);
}//for
*(data+len) = '\0';
/*
while ( d != NULL ) {
*(data+len) = *(d+len);
++len;
}//while
*/
}//String

int length() const {
return len;
}//length

char* begin() {
return data;
}//begin

friend ostream& operator<<(ostream& os, String& s) {
for( int i=0; i<s.length(); ++i ) {
os<<*(s.begin()+i);
}//for
os<<" ("<<s.length()<<")";
return os;
}//<<

};//String

#define HOLA
int main() {
#ifndef HOLA
cout<<"hola"<<endl;
#define HOLA
#endif
char *c = new char('c');
char *d = c;
cout<<"c-> "<<*c<<endl;
cout<<"d-> "<<*d<<endl;
delete [] d;
cout<<"c-> "<<*c<<endl;
cout<<"d-> "<<*d<<endl;

char tmp = 'c';
*d = tmp;
cout<<"d-> "<<*d<<endl;
d = &tmp;
cout<<"d-> "<<*d<<endl;
delete [] d;
cout<<"d-> "<<*d<<endl;

cout<<"String is "<<sizeof(String)<<" bytes or "<<sizeof(String)*8<<" bits long"<<endl;
String str("hello");
cout<<str<<endl;
return 0;
}//main