Please use the "Named Constructor Idiom".
See here :
http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Named_Constructor[
^]
For example, if you want allocate a memory only in heap :
class MyClass {
public:
static MyClass* create() { return new MyClass(); }
...
private:
MyClass();
...
};
int main()
{
MyClass* p = MyClass::create();
...
delete p;
...
}
If you want allocate a memory only in stack :
class MyClass {
public:
static void create()
{
MyClass myObj();
.....
}
...
private:
MyClass();
...
};
int main()
{
MyClass::create();
}
Regards,
Alex
P.S. Do not forget to vote if my answer helped you