dimanche 28 juin 2015

c++ translate from dynamic allocation to references

I have following code:

class A{
public:
    virtual do_something() = 0;
}

class B : public A{
public:
    virtual do_something() override;
}

void use_a(A *a){
   a->do_something();
   delete a;
}

use_a( new B() );

How this can be translated to references?
Notice do_something() is not const method. I thought it can be something like this:

void use_a(A &&a){
   a->do_something();
}

use_a( B() );

but someone told me this is bad style and must be avoided.

Aucun commentaire:

Enregistrer un commentaire