[Q] Template: Undefined Constructors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

    [Q] Template: Undefined Constructors

    Ok, this is very strange.

    in TRegionGrower.h , I've got:

    --
    template <class T>
    class TRegionGrower
    {
    public:

    TRegionGrower( void );
    ~TRegionGrower( void );
    };
    --

    In TRegionGrower.c p, I've got:

    --
    #include "TRegionGrower. h"

    template <class T>
    TRegionGrower<T >::
    TRegionGrower( void )
    {

    }



    template <class T>
    TRegionGrower<T >::
    ~TRegionGrower( void )
    {

    }
    --

    I use this class by doing:

    TRegionGrower<U Int8> regionGrower;

    I get two link errors telling me that the constructor and destructor are
    undefined.

    However, if I remove the constructor and destructors from the .cp file
    and change the .h file to:

    --
    template <class T>
    class TRegionGrower
    {
    public:

    TRegionGrower( void )
    {
    }

    ~TRegionGrower( void )
    {
    }
    };
    --

    The link errors go away.

    Any idea what might be going on here?


  • Russell Hanneken

    #2
    Re: [Q] Template: Undefined Constructors

    Eric wrote:[color=blue]
    >
    > I get two link errors telling me that the constructor and destructor are
    > undefined.
    >
    > However, if I remove the constructor and destructors from the .cp file
    > and change the .h file to:
    >
    > template <class T>
    > class TRegionGrower
    > {
    > public:
    >
    > TRegionGrower( void )
    > {
    > }
    >
    > ~TRegionGrower( void )
    > {
    > }
    > };
    >
    > The link errors go away.[/color]

    The FAQ addresses this issue:



    --
    Russell Hanneken
    rghanneken@pobo x.com
    Remove the 'g' from my address to send me mail.


    Comment

    • Claudio Jolowicz

      #3
      Re: [Q] Template: Undefined Constructors

      On Mon, 19 Apr 2004, Eric wrote:
      [color=blue]
      >Ok, this is very strange.
      >
      >in TRegionGrower.h , I've got:
      >
      >--
      >template <class T>
      >class TRegionGrower
      >{
      >public:
      >
      > TRegionGrower( void );
      > ~TRegionGrower( void );
      >};
      >--
      >
      >In TRegionGrower.c p, I've got:
      >
      >--
      >#include "TRegionGrower. h"
      >
      >template <class T>
      >TRegionGrower< T>::
      >TRegionGrowe r( void )
      >{
      >
      >}
      >
      >
      >
      >template <class T>
      >TRegionGrower< T>::
      >~TRegionGrower ( void )
      >{
      >
      >}
      >--
      >
      >I use this class by doing:
      >
      > TRegionGrower<U Int8> regionGrower;
      >
      >I get two link errors telling me that the constructor and destructor are
      >undefined.
      >[/color]

      1. How about giving us the definition of UInt8? With a sensible typedef,
      there shouldn't be any errors. If its a macro, anything is possible.

      2. Is the last line of code in a separate source file or in
      TRegionGrower.c p?

      3. What does the command line to (compile and) link the files look like?

      [color=blue]
      >However, if I remove the constructor and destructors from the .cp file
      >and change the .h file to:
      >
      >--
      >template <class T>
      >class TRegionGrower
      >{
      >public:
      >
      > TRegionGrower( void )
      > {
      > }
      >
      > ~TRegionGrower( void )
      > {
      > }
      >};
      >--
      >
      >The link errors go away.
      >
      >Any idea what might be going on here?
      >
      >
      >[/color]

      --
      Claudio Jolowicz


      Comment

      • Michiel Salters

        #4
        Re: [Q] Template: Undefined Constructors

        egusenet@verizo n.net (Eric) wrote in message news:<1gci5k9.1 7r0locvblnj0N%e gusenet@verizon .net>...[color=blue]
        > Ok, this is very strange.
        >
        > in TRegionGrower.h , I've got:
        >
        > --
        > template <class T>
        > class TRegionGrower
        > {
        > public:
        >
        > TRegionGrower( void );
        > ~TRegionGrower( void );
        > };
        > --
        >
        > In TRegionGrower.c p, I've got:[/color]
        [ the obvious implementation ]

        The FAQ reference in the previous post is correct, although there
        currently is an alternative solution. These templates need extra
        bookkeeping, as the FAQ explains. This is enabled using the export
        keyword on the class, but it is today only supported on the Comeau
        compiler.

        Regards,
        Michiel Salters

        Comment

        Working...