[Insight-users] Link problem with a template class.

Li, George (NIH/NCI) ligeorge at mail.nih.gov
Thu Apr 14 09:24:49 EDT 2005


Hi, Luis and all itk users:

I have made a new class for the Class RegistrationInterfaceCommand 
In the example of MultiResImageRegistration1.cxx for my program.
However, if the function of Execute() is implemented outside of
The template class definition, i.e. in the .cpp file, then there is
A link problem: complaining that this function is not defined.

In the cpp file, Execute() is defined as follows:

template <typename TRegistration>
void RegistrationInterfaceCommand <TRegistration>
::Execute(itk::Object * object, const itk::EventObject & event)
{
    if(typeid(event) != typeid(itk::IterationEvent)) {return;}

    RegistrationPointer registration =
                        dynamic_cast<RegistrationPointer>( object );

    OptimizerPointer optimizer = dynamic_cast< OptimizerPointer >( 
                       registration->GetOptimizer() );

    if(registration->GetCurrentLevel() == 0) {
      optimizer->SetMaximumStepLength( 16.00 );  
      optimizer->SetMinimumStepLength( 2.5 );
    }
    else {
      optimizer->SetMaximumStepLength( 
                optimizer->GetCurrentStepLength() );
      optimizer->SetMinimumStepLength(
                optimizer->GetMinimumStepLength() / 10.0 );
    }
}

However, it can pass the VC++6 compiler without problem. Strangely
Enough, if I placed an illegal statement, like "adfjalskfj;", inside
The function scope, the compiler does not even give me any error!

Currently, I have no choice but defining my Execute() function in
The header .h file. Any idea what went wrong?

Thanks,

George


More information about the Insight-users mailing list