Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vector_ref: Did he just forget to write the constructor or it is just a technique?

23 views
Skip to first unread message

Christiano

unread,
May 30, 2017, 3:56:53 PM5/30/17
to
PPP2 [1], appendix E, shows the following code:

//--------------begin-------------------------------
template<class T> class Vector_ref {
vector<T*> v;
vector<T*> owned;
public:
Vector_ref() {}
Vector_ref(T* a, T* b = 0, T* c = 0, T* d = 0); // <---- *HERE*

~Vector_ref() { for (int i=0; i<owned.size(); ++i) delete owned[i]; }

void push_back(T& s) { v.push_back(&s); }
void push_back(T* p) { v.push_back(p); owned.push_back(p); }

T& operator[](int i) { return *v[i]; }
const T& operator[](int i) const { return *v[i]; }

int size() const { return v.size(); }
};
//----------------end-------------------------------

The problem is the line:
Vector_ref(T* a, T* b = 0, T* c = 0, T* d = 0);

This constructor doesn't have definition. Did he just forget to write that constructor or it is just a technique?

____________
[1] http://www.stroustrup.com/Programming/

Paavo Helde

unread,
May 30, 2017, 4:19:53 PM5/30/17
to
On 30.05.2017 22:56, Christiano wrote:
> PPP2 [1], appendix E, shows the following code:
>
> This constructor doesn't have definition. Did he just forget to write
> that constructor or it is just a technique?

Maybe it was left as an exercise for the reader?
0 new messages