On 3 May, 06:47, pmouse <pmo...@cogeco.ca> wrote:
On May 2, 9:50 pm, newbie <mitbb...@yahoo.com> wrote:
(2)
class Example {
std::deque<MyData> *storage; // a pointer
public:
void Enque(MyData const& d)
{ storage->push_back(d); } // storing a copy
};
There is a case where you would want to keep your member data as
pointers, that's when you don't want to call the default constructor
on them, hence you create them manually.
For example, the stl containers takes iterator inputs as constructor
parameter, if you want to call those constructors, keep them as
pointers.
Are you suggesting a case where the OP's example 2 might be useful?
Because if so, I don't see what your getting at. I can have a
std::deque member and initialise it in any way I want.
#include <deque>
using namespace std;
class Example
{
public:
Example(deque<int>::iterator begin,
deque<int>::iterator end)
: storage(begin, end) {}
private:
deque<int> storage;
};
int main()
{
deque<int> d;
d.push_back(42);
Example e(d.begin(), d.end());
}
Gavin Deane