That will of course only work in C++11 and above, due to the default member initializer. However, by writing this, you are now required to provide (or =delete
) your copy/move constructors and assignment operators. Not to mention a destructor to delete this memory.
Which means you must decide on what copying behavior you want to have. Do you want to allow copying at all (and if not, you must use =delete
to signify that)? If so, what should a copy do? Since it's a pointer-const, you can't copy the pointer itself. At least, not in the copy-assignment case. So if you're copying, you now must copy the pointed-to object.
And thanks to your pointer-const, movement is flat-out impossible (without a const_cast
). So your move constructor/assignment will have to move the CustomList<Identifier*>
object, not merely the pointer to it.
Also, because of all of these user-defined operations, your ClassName
will no longer be considered a trivially copyable type. Though given that it stores a linked list, it probably wouldn't be trivially copyable either way.
So is this considered bad style? All things being equal, yes. Unless you have a genuine, well-considered reason to use a dynamic allocation, it's better and ultimately much safer programming style to just make it a value rather than a pointer:
CustomList<Identifier*> identifier_list("someString");