c++ - Programming Interview Example -


class string {  public:      string( char const* t ) : s(t) {}      ~string() { delete s; }      char const* c_str() const { return s; }  private:      char const* s;  };   

i asked memory problems above, don't @ memory don't program in c, had no idea, little know of c, thought problem there isn't explicit memory allocation , const * since wrong but, putting question here see other think.

from class definition not clear responsible deleting pointer. if argument of constructor pointer first character of string literal. in case using delete (more precisely delete[]) wrong.

also not clear whether pointer single character , delete has used or pointer first character of array , delete [] has used.

p.s. wonder why programmers example try resolve assignments in interview. interview not exam. if asked resolve assignment means dealing idiots not respect you. never assignment in interview.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

Bubble Sort Manually a Linked List in Java -

asp.net mvc - SSO between MVCForum and Umbraco7 -