This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

simple error woth templates


Hi,

I have made this program to learn templates, but gcc
keeps says that there's an undefined reference to
`Dog<int,long>::Dog[in-charge](int,int,long,log)` at
the line marked
bellow.
Could someone show me what's wrong?

Thanks in advance,

Andre


**** Dog.h *****

#ifndef IOSTREAM
  #define IOSTREAM
  #include <iostream.h>
#endif
 
template < class CLASS_A, class CLASS_B >
class Dog
{
  public:
    Dog( CLASS_A firstNumber, CLASS_A secondNumber,
CLASS_B thirdNumber, CLASS_B forthNumber );
    ~Dog(){};   
    void showBigger();

  private:
    CLASS_A number_A;
    CLASS_B number_B;
};


*** Dog.cpp ***

#ifndef DOG
  #define DOG
  #include "Dog.h"
#endif

template < class CLASS_A, class CLASS_B >
Dog< CLASS_A, CLASS_B >::Dog( CLASS_A firstNumber,
CLASS_A secondNumber, CLASS_B thirdNumber, CLASS_B
forthNumber )
{
  number_A = ( firstNumber>secondNumber
)?firstNumber:secondNumber;
  number_B = ( thirdNumber>forthNumber
)?thirdNumber:forthNumber;
}  

template < class CLASS_A, class CLASS_B >
void Dog< CLASS_A, CLASS_B >::showBigger()
{
  cout << number_A << endl;
  cout << number_B << endl;
}


*** main.cpp ***

#ifndef DOG
  #define DOG
  #include "Dog.h"
#endif

int main( int argc, char *argv[] )
{
  Dog < int, long > theDog( 10, 20, 30l, 40l );
  
//  theDog.showBigger;

  return( 0 );
}

__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]