[Insight-users] multiple definition error

Luis Ibanez luis.ibanez at kitware.com
Wed May 26 14:52:22 EDT 2010


Hi Baoyun,

Please find attached the fixed version of your code.

I didn't quite managed to replicate your report,...

but your troubles seems to be arising from your
definition of parameters in the template, and
very likely from the way you are invoking the
function.


Note that the template construction that you are
using is quite convoluted, and error prone.

You may want to reconsider simplifying it.



In particular,
templating a function over the type of Filter types
is unusual.


Another practice that you really want to avoid is

     template < class T>
     function(  std::vector< T > & value )



You could write a much cleaner version of this
code if you convert EmGmm into a real C++
class, and provide an "Execute()" or Compute()
method for it.


     Regards,


          Luis


---------------------------------------------------------------------------
On Wed, May 26, 2010 at 12:52 PM, Baoyun Li <baoyun_li123 at yahoo.com> wrote:

> Dear All:
>
> I want to add a small function into one of my template implemtation txx or
> cxx file. Before I add haha123(), I have no problem to build and run the
> project. After I add void haha123() into my txx file, I had multiple
> defintion error at the link stage.
>
> Belows are my .h file and .txx file for the template function. Can somebody
> teach me  how to figure out this problem.
>
> Thanks
>
> baoyun
>
>
> ############################my header file######################
>
>
>
> #ifndef _EmGmm_H
>
> #define _EmGmm_H
>
>
>
>
>
> #if defined(_MSC_VER)
>
> #pragma warning ( disable : 4786 )
>
> #endif
>
>
>
> #ifdef __BORLANDC__
>
> #define ITK_LEAN_AND_MEAN
>
> #endif
>
>
>
>
>
> #include "itkNumericTraits.h"
>
>
>
>
>
>
>
> template <int maximumnumberiteration,class TInputFilter,class
> TOutputFilter,class ParametersType,class PrototionType>
>
> void EmGmm( typename TInputFilter::Pointer& inputfilter,typename
> TOutputFilter::Pointer& labelreference,typename TOutputFilter::Pointer&
> outputfilter,std::vector<ParametersType>& initialparameters,PrototionType&
> initialProportions,std::string savedir);
>
>
>
> #ifndef ITK_MANUAL_INSTANTIATION
>
>  #include "EmGmm.txx"
>
>
>
> #endif
>
>
>
> #endif
>
>
>
>
>
> ############################my TXX file##################
>
> #ifndef _EmGmm_TXX
>
> #define _EmGmm_TXX
>
> #include "EmGmm.h"
>
>
>
> void haha123()
>
>
>
> {
>
>  ;
>
>
>
> }
>
>
>
> template <int maximumnumberiteration,class TInputFilter,class
> TOutputFilter,class ParametersType,class PrototionType>
>
> void EmGmm( typename TInputFilter::Pointer& inputfilter,typename
> TOutputFilter::Pointer& labelreference,typename TOutputFilter::Pointer&
> outputfilter,std::vector<ParametersType>& initialparameters,PrototionType&
> initialProportions,std::string savedir)
>
> {
>
>
>
>   ///// implementation of the function
>
>  // want to call void haha123
>
>
>
> }
>
>
>
>
>
>
>
> #endif
>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100526/7b17c9ce/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DuplicateSymbolFixed.tgz
Type: application/x-gzip
Size: 1112 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100526/7b17c9ce/attachment-0001.bin>


More information about the Insight-users mailing list