|
-
April 15th, 1999, 12:47 PM
#1
Changing this
Starting with a base class object and calling a method with a filename as an input. The idea is to find out what's inside the file and create an object of that type (the object inherits the base class). My problem is I want this of the base class object to become this of the specific class.
-
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);
}
-
April 16th, 1999, 11:16 AM
#3
Re: Changing this
It work !!! Thank you very much.
-
April 16th, 1999, 11:41 AM
#4
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
|