jeudi 3 octobre 2019

Assigning Values From One Pointer To An Array to Another Pointer To An Array

So I have a class defintion such that the private members are:

private:

    int size;
    int *bvect;                                 
    int bitlocations; 

I have a public constructor function such that:

BitVector::BitVector(const BitVector& a) {

    size = a.size;
    bvect = new int[size];
    for(int i = 0; i < size*32; i++)
        bvect[i] = a.bvect[i];
    bitlocations = a.bitlocations;

}

What this is trying to do, is create a new object that is idental to the object passed into the parameter a. My issue is lies in the for loop. Am I correctly setting the value found in bvect[i] to the value found in a.bvect[i]?

I DO NOT want the address to be the same. Only the values.

Thanks!

Aucun commentaire:

Enregistrer un commentaire