[C++-sig] convert child class to child class {lvalue} ?

English, Mark Mark.English at rbccm.com
Thu Oct 11 09:44:35 CEST 2007


> -----Original Message-----
> From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org]On
> Behalf Of Steven Wyckoff
> Sent: 10 October 2007 22:53
> To: c++-sig at python.org
> Subject: [C++-sig] convert child class to child class {lvalue} ?
> 
> 
> Hi all,
> 
> I am trying to wrap some C++ code that involves an object factory and 
> manager and I seem to be stumped by how boost is converting 
> types.
<snip>
> baseobj* createobj(std::string kind)
> {
>     if(kind == "Base")
>     {
>         return new baseobj();
>     }
>     else if(kind == "Child")
>     {
>         return new childobj();
>     }
>     else
>     {
>         return NULL;
>     }
> }
Haven't tested this myself, but try something like:
---C++ code---
boost::shared_ptr<baseobj> createobj(std::string kind)
{
    boost::shared_ptr<baseobj> ptrCreate;
    if(kind == "Base")
    {
        ptrCreate = new baseobj;
    }
    else if(kind == "Child")
    {
        ptrCreate = new childobj;
    }
    else
    {
        ptrCreate = NULL;
    }
    return ptrCreate;
}
________________________________________

This E-Mail (including any attachments) may contain privileged or confidential information.  It is intended only for the addressee(s) indicated above.

The sender does not waive any of its rights, privileges or other protections respecting this information.  

Any distribution, copying or other use of this E-Mail or the information it contains, by other than an intended recipient, is not sanctioned and is prohibited.

If you received this E-Mail in error, please delete it and advise the sender (by return E-Mail or otherwise) immediately. 

This E-Mail (including any attachments) has been scanned for viruses. 

It is believed to be free of any virus or other defect that might affect any computer system into which it is received and opened. 

However, it is the responsibility of the recipient to ensure that it is virus free. 

The sender accepts no responsibility for any loss or damage arising in any way from its use.

E-Mail received by or sent from RBC Capital Markets is subject to review by Supervisory personnel. 

Such communications are retained and may be produced to regulatory authorities or others with legal rights to the information.

IRS CIRCULAR 230 NOTICE:  TO COMPLY WITH U.S. TREASURY REGULATIONS, WE ADVISE YOU THAT ANY U.S. FEDERAL TAX ADVISE INCLUDED IN THIS COMMUNICATION IS NOT INTENDED OR WRITTEN TO BE USED, AND CANNOT BE USED, TO AVOID ANY U.S. FEDERAL TAX PENALTIES OR TO PROMOTE, MARKET, OR RECOMMEND TO ANOTHER PARTY ANY TRANSACTION OR MATTER.



More information about the Cplusplus-sig mailing list