[Insight-users] gradientCostFunction:: public SingleValuedCostFunction

Luis Ibanez luis.ibanez@kitware.com
Thu, 23 Jan 2003 14:42:40 -0500


Hi Digvijay

Thanks for sending your code.

The reason for the crash is that you are directly
invoking the constructor of the class instead of
using the "New()" method.

Please create your cost function as:

   MyCostFucntion::Pointer  function =
                          MyCostFunction::New();

right now you are doing:

        MyCostFunction function;

You could have avoid this problem by declaring
the constructor and destructor "protected".

Classes deriving from itk::Object should never
invoke their constructors or destructors explicitly.
Construction is done by "New()" and destruction
is managed by the reference counting and the
smart pointers.

Also, please never do:

          using namespace std;
          using namespace itk;

This is like having an expensive house,
with expensive doors and expensive locks
and...   leaving the door open.

Try to get used to specifying

       itk::    and     std::

You will end up liking how the code looks  :-)




Let us know if you find further problems,


Thanks


Luis


----------------------------------------


digvijay singh wrote:
> hi..!!
> the test apparently does not overload
> GetValueandDerivative() from
> SingleValuedCostFunction.cxx 
> i am sending over the dummy gradientCostFunction which
> does virtually nothing at all...(is never asked to do
> anything..so that should not be a problem ) and in
> main i try to create an object of this class and i
> still get the error ... there is nothing that i have
> added that could potentially cause the problem ,
> however there might be something that i am supposed to
> which i did not..kindly lemme know if thereis any such
> thing but from what is saw in
> SingleValuedCostFunction.cxx i could not locate a
> potential source of the problem..
> thanks
> digvijay