@AbstractionAnon Do you think about bool function , why? |
I don't understand your question. If you're asking if empty() should be a bool function, then yes. A String is either empty (true) or it's not (false). So a bool function makes perfect sense.
1 2 3
|
bool String::empty () const
{ return m_str ? my_len(m_str) == 0 : true; // m_str could be NULL
}
|
what is your advice about position of return true? |
I already answered that. The return true should go AFTER you have matched all the characters as being equal. i.e. put the return true at line 99.
Regarding your 2 errors, the line numbers (56,60) do not match up to the code you posted.
Line 56 is a blank line and line 60 is a return statement. Please provide line numbers that match up to the code you posted.
Edit:
Okay, I tried to compile your program. The errors I received were in main.cpp, not string.cpp.
(35): error C2440: 'initializing': cannot convert from 'void *' to 'char *' |
malloc returns a void *. You have to cast that to the type of left side of the assignment;
|
char* str = (char *)malloc(10);
|
Although I don't see the point of lines 35-36. They accomplish nothing.
(39): error C2440: 'initializing': cannot convert from 'const char *' to 'String' |
You have a constructor that takes a char *, but not a const char *. The compiler can not convert a const char * to a char *.