Marcel Wiesweg wrote:
.... It seems these two are not used in VDR except for one place (where I found this), cSectionHandler::SetChannel. The value stored by cSectionHandle has nid,tid,sid set to 0. In the line shp->channel = Channel ? *Channel : cChannel(); there seems only the operator= involved, but actually the copy constructor is invoked before the *Channel is given to opertator=. Attached is a short test program which illustrates the problem.
Solution is to make the copy constructor do copying.
Hi,
first thing, in your code, you should return *this in the operator= (and check if &a equals 'this'), which, I assume, you just forgot.
Now what the compiler does, is the following : Assume this snippet from your code : ... 1: A *pointer= &object; 2: A second; ... 3: second = pointer ? *pointer : A();
@3: The compiler creates a anonymous, automatic object for class A on compile-time and copies members from *pointer via its copy-constructor into it (setting d=0!). Then, the operator= gets called for second with the temporary object as an argument (hence, copying d=0 into second).
Try the attached code, which'll make it clearer, I presume...
Apparently, the copy-constructor in cChannel needs explanation...