المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Using dynamic_cast for Clist



C++ Programming
08-25-2009, 10:17 AM
Please I need help on this, I'm new in C++.

Here are the details:
1. I have a base class and 3 derived classes:

Base class
class CRepositoryData
{
...
};
Derived classes
class CUser_data : public CRepositoryData
{
...
};
class CLock_data : public CRepositoryData
{
...
};
class CReferences_data : public CRepositoryData
{
...
};

2. My declaration for my classes in my function uses CList
main()
{
CList listLockDataTemp_L;
CList list********DataTemp_L;
CList listUserDataTemp_L;

if(Lock)
{
CreateBatchToSend(
dynamic_cast(&listLockDataTemp_L));
}else if(CReferences)
{
CreateBatchToSend(
dynamic_cast&list********DataDataTemp_L));

}else
CreateBatchToSend(
dynamic_cast(&listUserDataTemp_L));

}

}

3. Is this code possible for my CreateBatchToSend()?

BOOL CreateBatchToSend(CList *pListRepData_P)
{
...
CList listLockDataTemp_L;
listLockDataTemp = dynamic_castpListRepData_P;
...
}


4. I am trying to create a function that can take those 3 derived classes in a list by using the base class as the argument and then use dynamic cast to revert back to their respective class.
Do I need to use other containers to implement this?

Any suggestions would be very helpful. Thanks a lot...