Casting a list

Abizar Abizar@stts.com.sg
Wed Apr 3 00:45:00 GMT 2002


Hi,

Is it safe to do the following(3rd last line): (I apologise for the long
message.)
Compiler: gcc3.0.3
OS: RedHat 7.2
Architecture: i386

class Fruit
{
}

class Basket
{
  public:
    add(list<Fruit*>& fruits);
}

class Apple : public Fruit
{
}

class AppleTree
{
  public:
    list<Apple*>* getApples() { return &myApples; }
  private:
    list<Apple*> myApples;
}

The above classes cannot be modified.


class AppleBasket : Basket

  public:
    void doWork(AppleTree* appleTree)
    {
       list<Apple*>& apples = *appleTree.getApples();
       add((list<Fruit*>&)apples);                 <------ is this line
safe???????
    }
}

Any help will be much appreciated.

Thanks & Best Regards,

Abizar Basrai
Software Engineer
ST Training & Simulation Pte Ltd
Singapore



More information about the Libstdc++ mailing list