K
karlman
Hello!
Here's a question regarding templates:
Suppose I have these three files containing the following:
print.hpp:
template < typename T >
void print( T x );
print.cpp:
template <typename T>
void print( T x )
{
std::cout << x << std::endl;
}
driver_print.cpp:
#include "print.hpp"
int main()
{
print( "Whazz up!" );
print( 134 );
return 0;
}
This doesn't work neither with g++ (3.x.x) nor bcc32 (5.5.1).
But when you change the files to the following it works:
print.hpp:
template < typename T >
void print( T x )
{
std::cout << x << std::endl;
}
driver_print.cpp:
#include "print.hpp"
int main()
{
print( "Whazz up!" );
print( 134 );
return 0;
}
The book I'm reading warns you of this, but I'm interested in why is this
so.
Thank you for your answers,
Karlo.
Here's a question regarding templates:
Suppose I have these three files containing the following:
print.hpp:
template < typename T >
void print( T x );
print.cpp:
template <typename T>
void print( T x )
{
std::cout << x << std::endl;
}
driver_print.cpp:
#include "print.hpp"
int main()
{
print( "Whazz up!" );
print( 134 );
return 0;
}
This doesn't work neither with g++ (3.x.x) nor bcc32 (5.5.1).
But when you change the files to the following it works:
print.hpp:
template < typename T >
void print( T x )
{
std::cout << x << std::endl;
}
driver_print.cpp:
#include "print.hpp"
int main()
{
print( "Whazz up!" );
print( 134 );
return 0;
}
The book I'm reading warns you of this, but I'm interested in why is this
so.
Thank you for your answers,
Karlo.