Constructor Definition

Posted by mctl87 on Stack Overflow See other posts from Stack Overflow or by mctl87
Published on 2011-01-01T15:27:41Z Indexed on 2011/01/01 15:54 UTC
Read the original article Hit count: 155

Filed under:
|
|

Ok so i have a class Vector:

#include <cstdlib>

class Vec
{
private:
    size_t size;
    int * ptab;

public:
    Vec(size_t n);
    ~Vec() {delete [] ptab;}

    size_t size() const {return size;}
    int & operator[](int n) {return ptab[n];}
    int operator[](int n) const {return ptab[n];}

    void operator=(Vec const& v);
};

inline Vec::Vec(size_t n) : size(n), ptab(new int[n])
{ }

and the problem is that in one of my homework exercises i have to extend constructor def, so all elements will be initialized with zeros. I thought i know the basics but cant get through this dynamic array -.-

ps. sry for gramma and other mistakes ;)

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework