2021-05-30

C++ static creator function that returns a null pointer if the parameter is invalid [closed]

I'm writing a class that doesn't provide a public constructor. Instead the user must create object through a creator function that takes some arguments. The creator function returns a pointer to the object if the passed arguments are valid and 'new' works, and a null pointer if the passed arguments are invalid or 'new' doesn't work.

I know I can use a static creator function, but this way I wouldn't be able to initialize the fields from the passed arguments.

What are some possible ways?



from Recent Questions - Stack Overflow https://ift.tt/3hXUnlE
https://ift.tt/eA8V8J

No comments:

Post a Comment