Sign in
Log inSign up

Silly doubt C++

Aakash Mallik's photo
Aakash Mallik
·Jan 9, 2018

I just started shifting from Java to C++ and I am having a hard time with the C++'s subtle syntax. I was writing this code:

class Box{
    public:
        int length;
        int width;

        // a few more function over loaded constructors        

        Box( Box box_object_to_copy ){
            this->length = box_object_to_copy.length;
            this->width = box_object_to_copy.width;
        }
};

I am running into compilation error. I am not sure, but my friend pointed out that the constructor taking the Box object is at fault as it is not taking the object as reference. But my point is reference or value, it should work at least. Passing by value basically creates another copy, that is the only immediately visible difference between the two...