View Single Post
Old 09-10-2004, 12:44 AM   #5 (permalink)
n0nsensical
Junkie
 
Location: San Francisco
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
Code:
Foo f;
Bar b = f;
wouldn't compile either for the same reason.

Last edited by n0nsensical; 09-10-2004 at 12:47 AM..
n0nsensical is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73