[Solved] How do I write the copy Constructor for Composition? [closed]

Try like this: #include <string> #include <iostream> class Pulley{ private: int noOfTeeth; public: Pulley(int teeth = 0); void show(); }; Pulley::Pulley(int teeth) : noOfTeeth(teeth) { std::cout << “Pulley constructor called!”; } void Pulley::show() { std::cout << “\n\nNo of Teeths of Pulley: ” << noOfTeeth; } class GearBox{ private: std::string transmission; Pulley p; public: GearBox(std::string trans … Read more

[Solved] Copy Constructor Issue C++: “0xC0000005: Access violation writing location 0x00000000.”

you are passing reference to orig. you should use ‘orig.bigIntVector’ BigInt::BigInt(BigInt const& orig) : isPositive(orig.isPositive) , base(orig.base) , skip(orig.skip) { this->bigIntVector = new BigIntVector(*(orig.bigIntVector)); } should use *(orig.bigIntVector) 10 solved Copy Constructor Issue C++: “0xC0000005: Access violation writing location 0x00000000.”