C
C. Carbonera
/*
Hi,
I have a problem with explicit instantiation of templates in Visual
C++ 6.0.
I have provided the source below. I have an example of a function
template that produces incorrect output in the code below.
The function
template < typename T >
void DummyFunctionDoesNotWork(T &o);
Produces incorrect output. The following is the expected output:
First Type
Second Type
But, instead, I obtain the following is the output:
Second Type
Second Type
I have written a second function
template < typename T >
void DummyFunctionWorks(T &o);
That produces the correct output.
Could someone please test the code given below in Visual C++.NET
and let me know if it works?
Thanks,
CCarbonera
*/
#include <fstream.h>
enum explicit_t
{first_t=1,
second_t=0};
template <explicit_t t>
struct Dummy
{
const char* operator()(void){ return " UNDEFINED "; };
};
template <>
const char* Dummy< first_t >:perator()(){ return " First Type "; }
template <>
const char* Dummy<second_t>:perator()(){ return " Second Type "; }
template < typename T >
void DummyFunctionWorks(T &o)
{ cout << o() << endl; }
template < typename T >
void DummyFunctionDoesNotWork()
{ T o; cout << o() << endl; }
void main(int argc, char* argv[])
{
cout<< "The following produces the correct output:" << endl;
Dummy<first_t> frst;
Dummy<second_t> scnd;
DummyFunctionWorks < Dummy< first_t > > ( frst );
DummyFunctionWorks < Dummy< second_t > > ( scnd );
cout<< "The following produces the wrong output:" << endl;
DummyFunctionDoesNotWork < Dummy < first_t > > ( );
DummyFunctionDoesNotWork < Dummy < second_t > > ( );
}
Hi,
I have a problem with explicit instantiation of templates in Visual
C++ 6.0.
I have provided the source below. I have an example of a function
template that produces incorrect output in the code below.
The function
template < typename T >
void DummyFunctionDoesNotWork(T &o);
Produces incorrect output. The following is the expected output:
First Type
Second Type
But, instead, I obtain the following is the output:
Second Type
Second Type
I have written a second function
template < typename T >
void DummyFunctionWorks(T &o);
That produces the correct output.
Could someone please test the code given below in Visual C++.NET
and let me know if it works?
Thanks,
CCarbonera
*/
#include <fstream.h>
enum explicit_t
{first_t=1,
second_t=0};
template <explicit_t t>
struct Dummy
{
const char* operator()(void){ return " UNDEFINED "; };
};
template <>
const char* Dummy< first_t >:perator()(){ return " First Type "; }
template <>
const char* Dummy<second_t>:perator()(){ return " Second Type "; }
template < typename T >
void DummyFunctionWorks(T &o)
{ cout << o() << endl; }
template < typename T >
void DummyFunctionDoesNotWork()
{ T o; cout << o() << endl; }
void main(int argc, char* argv[])
{
cout<< "The following produces the correct output:" << endl;
Dummy<first_t> frst;
Dummy<second_t> scnd;
DummyFunctionWorks < Dummy< first_t > > ( frst );
DummyFunctionWorks < Dummy< second_t > > ( scnd );
cout<< "The following produces the wrong output:" << endl;
DummyFunctionDoesNotWork < Dummy < first_t > > ( );
DummyFunctionDoesNotWork < Dummy < second_t > > ( );
}