Original Post
Hi,
I've hit the latest snag in my book and seeing as I don't have a C++ tutor to hand I thought I'd come on here and ask a few questions. Here's the code:
The bit I really don't get at the moment is this line:
This *looks* to me like a constructor which takes one argument with variable name 'capacity'. I am interested in the fact that the variable type size_t is not declared until later though inside the class definition. Is this legal? Can you declare a variable type as an argument to a constructor when that variable type is only defined inside the class?
I do have more questions but I'd like to work through this one first. Thanks.
I've hit the latest snag in my book and seeing as I don't have a C++ tutor to hand I thought I'd come on here and ask a few questions. Here's the code:
template <typename T>class PtrVector { public: explicit PtrVector(size_t capacity) : buf_(new T *[capacity], cap_(capacity), size_(0) {} private: T **buf_; // ptr to array of ptr to T size_t cap_; // capacity size_t size_; // size};The bit I really don't get at the moment is this line:
explicit PtrVector(size_t capacity) : buf_(new T *[capacity], cap_(capacity), size_(0) {}This *looks* to me like a constructor which takes one argument with variable name 'capacity'. I am interested in the fact that the variable type size_t is not declared until later though inside the class definition. Is this legal? Can you declare a variable type as an argument to a constructor when that variable type is only defined inside the class?
I do have more questions but I'd like to work through this one first. Thanks.