From Darin McBride · 1996-04-04 02:18 · #73661 in EMULATE
EB> In a msg on <Apr 01 21:56>, to Chris Downs, Darin McBride writes:
DM> char* operator()()
DM> {
DM> return pchar;
DM> }
EB> FWIW, in addition to the observations Chris Downs made,
EB> you might want to omit this cast. Otherwise you can do things like this:
EB> const cchar rock("I shall never change.");
EB> ((char *)rock)[0] = '\0'; // "never" comes early... ;-)
Are you sure? 'char* operator()()' is not 'char* operator()() const' so, I thought (wrongly?), it wouldn't be called. Ack. THEN AGAIN...
The point was that 'cchar' would be more like 'char*' and 'char[]'. Thus a 'const cchar' would be much like a 'const char*', not 'char* const'. This means things like:
const char* pch = "I shall never change.";
pch[0] = '\0'; // "never" comes early...
works, but, later in the same code,
pch = "Can I point here?";
does NOT work because of the const.
I can understand the 'conflict' - this class wasn't meant to be an object to the full extent possible under C++ (where I think the 'ideal' C++ string class would be much better), only to make some operations with char*'s a little easier to manage... including auto-delete and quick changes of contents.
DM> inline ostream& operator << (ostream& os, cchar& cc)
DM> {
DM> return os << cc.pchar;
DM> }
EB> Since you already have a cast from cchar to const char
EB> * defined, you don't really need this, do you?
I did at one time, but it seems the new version of GCC complains about it. It's gone. :-)
--- Maximus/2 3.01
* Origin: Tanktalus' Tower BBS (PVT) (1:342/708)