See the highlighted portion (in yellow) the definition of copyConstructor at http://libraryofcprograms.blogspot.com/2013/03/copyconstructor.html
Why haven't we used obj.getX() ?

void a::copyConstructor(a &obj){
    x  =  obj.x; //should have used obj.getX() because we're accessing a private member of obj?
}

All member functions of a class can access all data members and all other member functions of that class, no matter what their access level (public, private etc.), and no matter which object of that class they are in. The copy constructor does not need to use the public interface functions to have access to the other object's data.

The intent here is that whoever is writing the class knows how it is supposed to work, but someone else is just going to use its public interface to get objects of the class to do things. If you change how the interior works, without changing the public interface, none of the functions external to the class need to be modified, but the member functions of the class would be changed to accomodate the new internal design.

commented: Agreed! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.