Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Sunday, October 9, 2011

new and constructors

C++ is not C# - these two forms have different effects

{
A v = A(9);
A *w = new A(8);
}


The first one constructs a temporary A and assigns it to v. Constructor A(int) is called exactly once, and when v goes out of scope, ~A is called.

The second one allocates an A-sized piece of memory, constructs a temporary A, assigns it to that piece of memory, and sets w to point to it. Constructor A(int) is called exactly once, but when w goes out of scope, ~A is not called. The only destructor that would get called here is the one for type A*, and A* isn't a class so either there isn't one, or there is one that does nothing. Either way it isn't what you want.

Followers

Blog Archive