I have an function in which I want to make a copy of an object.

ClassBase
{
public:
Tblk myTblk;
private:

};

void ClassBase::CopyObject(const ClassBase &test)
{
       TblkPtr_t myTblk = TblkPtr_t(new Tblk); //TblkPtr_t is a typedef shared pointer
      *myTblk = *test.myTblk;
}

For some reason that doesn't work. If I use the copy constructor like this

myTblk = new Tblk(*test.myTblk)

then it seems to work. I don't understand why if I dereference the pointer in my original example why it wouldn't work. Can someone enlighten me?

Your copy ctor is hiding the member variable. And even worse you have
a memory leak.

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.