Trying to create a class that can be instantiated only in heap.
class Test1
{
Test1();
Test1(const Test1 &);
public:
static Test* getObject()
{
return new Test();
}
};
int main()
{
Test1* ptr1 = Test1::getObject();
}
error:
ObjectOnHeapOnly.cpp:39:12: error: cannot initialize a variable of type 'Test1 *' with an rvalue of type 'Test *'
Test1* ptr1 = Test1::getObject();
^ ~~~~~~~~~~~~~~~~~~
1 error generated.
Aucun commentaire:
Enregistrer un commentaire