Constructor return value

Posted by Ivan Gromov on Stack Overflow See other posts from Stack Overflow or by Ivan Gromov
Published on 2010-04-05T18:58:07Z Indexed on 2010/04/05 19:03 UTC
Read the original article Hit count: 222

Filed under:
|

Could you tell me what is wrong with my class constructor? Code:

CVector::CVector (int size_)
{
    if (size_ > 0)
    {
        this->size = size_;
        this->data = new double[size];
        for (int i = 0; i < size; i++)
        {   
            (*this)(i) = i;
        }
    }
    cout << "constructor end" << endl;
    return;
}

Usage example:

tvector = CVector(6);

I get an access violation after "constructor end" output.

© Stack Overflow or respective owner

Related posts about c++

Related posts about constructor