Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 11-10-2008, 09:16 AM   #31
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

Quote:
Originally Posted by Japofran View Post

As a matter of fact using an overloaded assignment operator with a string is not a C-ism at all... Actually the robust C code to clear a string or check if it's not empty is very brief and immediately recognizable:

Code:
*templine = '\0';
Code:
while ( *templine != '\0' );
(Actually I could write just 0 instead of '\0', couldn't I? Hm better safe than sorry.) Of course templine would here be a C string (pointer to char), not a string object. I can't do this stuff with objects and I'm not supposed to, their innards are "private".
You are totally right about the fact that using the overloaded operators is very C++ like and not C like, however for a starting programmer (for those I posted this very simple piece of code), it can be confusing and might lead to bad practices with other objects.
Maybe i should use string.append instead of the += as well.... but it doesn't make the code look more beautiful in my opinion. In my code not intended for newbies you will find lot's of classes in which I overloaded the operators in order to keep their usage intuitive. (So you don't need to learn an interface before you can use it)


You could use 0 instead of '\0' I always use 0., but this comes mainly from the fact that
in C++ NULL and 0 are the same, so I can stick with one type of 0 for everything.

I could ramble on about objects and stuff and as well, but that has fairly little to do with the solved problem.

Thank you for your discussion so far. I really appreciate it.
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
 


Similar Threads
Thread Thread Starter Forum Replies Last Post
Castlevania movie script revealed TheChosen Blah, blah, blah... 16 18-07-2008 06:41 PM
Abandonia Script? jourdan Old Suggestions 4 09-07-2007 09:24 AM
Script Not Working After Migrate Reup Old Suggestions 1 25-08-2006 11:58 AM
Annoying Script Prompt -RESOLVED guesst Old Suggestions 7 28-07-2006 01:00 AM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 12:07 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.