2016-09-05 9 views
-2

現在、C++ Primer 5th Ed。今日私は動的メモリを扱うクラスについての章に達しました。以下の概念、与えられた:カスタムクラス(ベクトル<string>のシンプルバージョン、アロケータを使用したRange-forループ)

class StrVec{ 

    public: 

    StrVec() : // the allocator member is default initialized 
     elements(nullptr), 
     first_free(nullptr), 
     cap(nullptr) {} 

    StrVec(const StrVec&); 

    StrVec(std::initializer_list<std::string>); 

    StrVec& operator=(const StrVec&); 

    ~StrVec(); 
    std::string*  begin()  const  { return elements; } 
    std::string*  end()  const  { return first_free; } 
    //other functions 

    private: 

    std::allocator<std::string> alloc; 

    std::string *elements; 

    std::string *first_free; 

    std::string *cap; 

    //other functions 

}; 

そしてStrVecオブジェクトStrVec foo={"stack","overflow"}、どのように範囲-のための正確ループ作業(for(auto& el : foo) std::cout<<el<<std::endl)。私が繰り返す「もの」は何ですか?

+4

ダイナミックメモリの割り当てや[ループの範囲]について質問していますか(http://en.cppreference.com/w/cpp/language/range-for)? –

+3

ループの範囲に必要なキーメンバー関数を省略しました...実際に何を求めていますか? – LogicStuff

+2

何かこの質問に対する答えです。 –

答えて

1

私が繰り返す「もの」とは何ですか?

foo.begin()foo.end()の結果によって区切られる範囲。

はい、これらの関数名はその点で「特別」です。それを標準で承認された大会と呼んでください。

+0

Orbitの@BiffenとLightnesss Racesの回答に感謝します。 – JohhnieWH

関連する問題