CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Changing this

  1. #1
    Guest

    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.


  2. #2
    Join Date
    Apr 1999
    Posts
    90

    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);
    }



  3. #3
    Guest

    Re: Changing this

    It work !!! Thank you very much.


  4. #4
    Join Date
    Apr 1999
    Posts
    90

    Re: Changing this

    My pleasure!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured