alternative to strdup

Posted by Alexander on Stack Overflow See other posts from Stack Overflow or by Alexander
Published on 2010-03-14T22:35:27Z Indexed on 2010/03/14 22:45 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

I am using strdup here to copy the value of the parameter name into nm in the constructor... is there an alternative of achieving the same result without using strdup and without using the C++ STL library and using the keyword new instead?

Book::Book(const char *name, int thickness, int weight):nm(NULL), thck(thickness), wght(weight){
  if(name)
        nm =  strdup(name);
}

class Book {
private:
  char* nm;
..........
............
..........
...........
};

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++