Has been answered, but I typed it and posted it and its staying. =P
Quote:
Originally Posted by KnifeMissile
Now, for clarification (at least one of you seems to need it), I expect different struct declarations to be considered different types (hence, my statement about "(correctly, IMO) fails to compile"). My question was why templated structs aren't considered different types...
It's tempting to debate the merits of C++ versus Java but that would honestly diverge from the thread topic and risk starting a religious flame war...
|
Different declarations
are considered different types in the same way for templated classes, but those two code segments are not really equivalent. In the first example, Foo and Bar are two completely seperate types. In the second, Value<int> is the one and only type; the typedef statements don't create new types, just new names for the same one. An equivalent example for the templated class would be something like:
Code:
template<class T> struct s1
{
T x;
};
template<class T> struct s2
{
T x;
};
typedef s1<int> Foo;
typedef s2<int> Bar;
Then
wouldn't compile either for the same reason.