alternative to strdup
- by Alexander
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;
..........
............
..........
...........
};