|
-
April 15th, 1999, 02:53 PM
#2
Re: Changing this
What about creating a static function that returns an allocated pointer to the base class? Within this function you would call new using the correct derived class after determining the file contents.
For example:
class CBase
{
public:
CBase();
static CBase *Create(const CString &strFilename);
};
CBase *CBase::Create(const CString &strFilename)
{
CBase *pRetVal = NULL;
// determine file type
...
// allocate object of correct derived class
pRetVal = new CDerived;
// return allocated pointer to object
return(pRetVal);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|