IonicWind Snippit Manager 2.xx Released! Install it on a memory stick and take it with you! With or without IWBasic!
Started by Parker, March 02, 2007, 10:10:09 PM
0 Members and 1 Guest are viewing this topic.
class DynStringprivate pointer pstr uint allocsize uint s_lengthpublic declare DynString( ) declare _DynString( ) declare set( DynString s ) declare setz( string s ) declare append( DynString s ) declare appendz( string s ) declare c_str( ), string declare length( ), intend classsub DynString::DynString( ) pstr = new(char, 1) allocsize = 1 s_length = 0end subsub DynString::_DynString( ) delete pstrend subsub DynString::set( DynString s ) setz( s.c_str( ) )end subsub DynString::setz( string s ) uint slen : slen = len( s ) if slen = 0 then *<char>pstr = 0 s_length = 0 end if if slen >= allocsize then allocsize = slen + 1 delete pstr pstr = new( char, allocsize ) end if *<string>pstr = s s_length = slenend subsub DynString::append( DynString s ) appendz( s.c_str( ) )end subsub DynString::appendz( string s ) uint slen : slen = len( s ) if slen + s_length >= allocsize then if 2 * allocsize > slen then _ allocsize *= 2 _ else _ allocsize += slen * 2 pointer temp : temp = new( char, s_length + 1 ) *<string>temp = *<string>pstr delete pstr pstr = new( char, allocsize ) *<string>pstr = *<string>temp delete temp end if *<string>pstr += s s_length += slenend subsub DynString::c_str( ) return *<string>pstrend subsub DynString::length( ) return s_lengthend sub'' test codeDynString dstrdstr.setz( "Hello" )print dstr.length( ), dstr.c_str( )dstr.appendz( " World" )print dstr.length( ), dstr.c_str( )do:until inkey$()<>""
Quote from: Parker on March 02, 2007, 10:10:09 PM (in fact, there are almost no classes period )
Quote from: LarryMc on June 03, 2015, 01:59:52 PM1) what do you mean "it fails"? Be specific!2) do you mean an application or do you really mean a "project"? read the help manual section on projects and the tutorial on projects and try to set one up first and then ask your questions?3)At least one of your class methods doesn't match your declaration.Is this some important part of a something important you are working on or is this just something you are playing around with.I really don't have time to spend time on this right now unless it is really, really important; and you will have to explain to me why it is that important right now.