2016-08-14 8 views
1

のコレクションをstd::tupleに保存しています。しかし、タプルから要素を取得して変更すると、返された要素のコピーのみを変更しています。そう、それ自体でオートを使用してstd :: tupleからの参照ではなくコピーの取得

ecs::component::ComponentStore<ecs::component::Position, ecs::component::Velocity> comstore; 

//Get the position vector 
auto positionvec = comstore.Get<ecs::component::Position>(); 
//Add a new position 
positionvec.emplace_back(ecs::component::Position{}); 


//Later on, get the position vector again 
auto positionvec2 = comstore.Get<ecs::component::Position>(); 

//But it's empty??? this is wrong. It should have 1 element. 

答えて

4

、あなたが推測非参照型の変数を作成

auto positionvec = comstore.Get<ecs::component::Position>(); 

template<typename... Ts> 
class ComponentStore 
{ 
public: 
    ComponentStore() 
    { 

    } 
    ~ComponentStore() 
    { 

    } 

    template<typename T> 
    std::vector<T>& Get() 
    { 
     return std::get<std::vector<T>>(m_components); 
    } 

private: 
    std::tuple<std::vector<Ts>...> m_components; 
}; 

これは私がComponentStoreクラスを使用する予定の方法です

は新しいベクトルを作成します。

auto& positionvec = comstore.Get<ecs::component::Position>(); 

あなたは自動&を使用してこの問題を解決することができます

関連する問題