Of course; just make the constructor private (protected if it is a base class):
class A {
public:
static A* newA()
{
return new A();
}
private:
A() {}
};
You should also make the copy constructor private / secure, if necessary.
And as always, you should strongly consider returning a smart pointer rather than a raw pointer to simplify memory management issues.
source
share