I
Imre
Let's suppose we have a primary template with one argument defined in a
header file. Two source files include this header, and both define a
specialization of the primary template. Later, both sources reference
the template, using the same template argument, that matches both
specializations. Now, in theory, both sources reference the same
template with the same argument, but due to the different
specializations in the sources, the exact meaning of these seemingly
identical references should be different.
For example:
// --- MyTemplate.h ---
template <int i>
struct MyTemplate
{
enum { value = -1 };
};
// --- One.cpp ---
#include "MyTemplate.h"
template <>
struct MyTemplate<0>
{
enum { value = 1 };
};
int i1 = MyTemplate<0>::value;
// --- One.cpp ---
#include "MyTemplate.h"
template <>
struct MyTemplate<0>
{
enum { value = 2 };
};
int i2 = MyTemplate<0>::value;
Now i1 should be 1, and i2 should be 2.
My questions are:
1. According to the standard, should this work?
2. Is this likely to work on compilers that use a template repository?
Imre
header file. Two source files include this header, and both define a
specialization of the primary template. Later, both sources reference
the template, using the same template argument, that matches both
specializations. Now, in theory, both sources reference the same
template with the same argument, but due to the different
specializations in the sources, the exact meaning of these seemingly
identical references should be different.
For example:
// --- MyTemplate.h ---
template <int i>
struct MyTemplate
{
enum { value = -1 };
};
// --- One.cpp ---
#include "MyTemplate.h"
template <>
struct MyTemplate<0>
{
enum { value = 1 };
};
int i1 = MyTemplate<0>::value;
// --- One.cpp ---
#include "MyTemplate.h"
template <>
struct MyTemplate<0>
{
enum { value = 2 };
};
int i2 = MyTemplate<0>::value;
Now i1 should be 1, and i2 should be 2.
My questions are:
1. According to the standard, should this work?
2. Is this likely to work on compilers that use a template repository?
Imre