jeudi 11 juin 2015

What's a good way of Factory's create method in c++11?

Now I'm developing a c++ project. And I don't know what's a good way of c++ Factory's create method. My environment is below.

Environment:

  • gcc 4.8.2 g++
  • built with std=c++11 option

I've created a Item class its instances are created by MyFactoryClass.

class Item {
public:
  void hoge();
private:
  int fuga;
  string foo;
};

In this case, what's a good way to implement create method? In general later method is good, but I've heard RVO in recent c++. So do both ways are no problems? And if there are better ways, I'd love to hear your examples.

static Item createItem(int id);
static void createItem(int id, Item& item);

Aucun commentaire:

Enregistrer un commentaire