Here the full sample
And output isCode:#include<iostream> class String { char * ps; int siz; int len; public: String(const char * psz) { siz = strlen(psz)+1; ps = new char[siz]; strcpy(ps, psz); } ~String() { delete []ps; } const char * c_str() { return ps; } friend class StringIterator; }; class StringIterator { int pos; String * s; public: StringIterator(String & str) : s(&str), pos(0) {} char & operator*() { return s->ps[pos]; } StringIterator& operator++(int) { pos++; return *this; } }; int main() { char * q = "Hello"; char buf[20] = { '\0' }; char * p = buf; while (*p++ = *q++); std::cout << buf << std::endl; String s("World"); String t(" "); StringIterator i(s); StringIterator j(t); while (*j++ = *i++); std::cout << t.c_str() << std::endl; return 0; }
Hello
orld
Regards, Alex
P.S.
I don't think the above is a real problem. However, it was that what invoked me to not using post-increment on class types anymore.




Reply With Quote