現在、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
)。私が繰り返す「もの」は何ですか?
ダイナミックメモリの割り当てや[ループの範囲]について質問していますか(http://en.cppreference.com/w/cpp/language/range-for)? –
ループの範囲に必要なキーメンバー関数を省略しました...実際に何を求めていますか? – LogicStuff
何かこの質問に対する答えです。 –