M
muley.rahul
Hi
can i call a constructor of a class, if the name is stored in a CString
Object
e.g.
class CBaseClass
{
int x;
};
class CDerClass1: public CBaseClass
{
int y;
};
class CDerClass2: public CBaseClass
{
int z;
};
CString strClassName;
// = L"CMyClass";//using unicode charset....
//main1//i know this
CBaseClass* pPtr;
------
----
----------
if(some condition)
{
strClassName = L"CDerClass1"
pPtr = new CDerClass1;
}
else
{
strClassName = L"CDerClass2"
pPtr = new CDerClass2;
}
//for 2 classes this approach is fine but
//what if i have more than 100 classes derived from the same class
//n at runtime i want to allocate the memory for them.....
//main2//can it be done????
CBaseClass* pPtr;
------
----
----------
if(some condition)
{
strClassName = L"CDerClass1"
}
else
{
strClassName = L"CDerClass2"
}
//now i want to allocate the memory for the class whose name is stored
in the strClassName
pPtr = new "some way to call the constructor whose name is stored in
string.....";
plz help me i m tired of writting this if else statements........
can i call a constructor of a class, if the name is stored in a CString
Object
e.g.
class CBaseClass
{
int x;
};
class CDerClass1: public CBaseClass
{
int y;
};
class CDerClass2: public CBaseClass
{
int z;
};
CString strClassName;
// = L"CMyClass";//using unicode charset....
//main1//i know this
CBaseClass* pPtr;
------
----
----------
if(some condition)
{
strClassName = L"CDerClass1"
pPtr = new CDerClass1;
}
else
{
strClassName = L"CDerClass2"
pPtr = new CDerClass2;
}
//for 2 classes this approach is fine but
//what if i have more than 100 classes derived from the same class
//n at runtime i want to allocate the memory for them.....
//main2//can it be done????
CBaseClass* pPtr;
------
----
----------
if(some condition)
{
strClassName = L"CDerClass1"
}
else
{
strClassName = L"CDerClass2"
}
//now i want to allocate the memory for the class whose name is stored
in the strClassName
pPtr = new "some way to call the constructor whose name is stored in
string.....";
plz help me i m tired of writting this if else statements........