Template question...
Say I create a template:
template
class Dilly
{
...
}
Then I create a specialization of this template:
template
class Dilly
{
...
}
Now, here''s the question, when I create a typedef of an int, will the template generated be of int type, or of type TypedefName?
typedef int Dally;
Dilly dd;
Will dd be of type Dilly or Dilly?
Thanks.
farmersckn
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Ummm... before I can answer, let me fix some things. I don''t see any difference in your two template definitions. The other problem is when you declare your templated classes. It should be:
So regarding your first question, Dilly won''t be of type anything cuz you don''t give it any type. Now your second question is confusing and I''m not sure if you phrased it correctly, so can''t answer. I think you "specialize" a template by doing this:
So now you can use "DillyDally" in place of "Dilly".
This is how STL works. Everything is a template and most classes are typedef-ed versions of those templates.
Jinushaun
|
So regarding your first question, Dilly won''t be of type anything cuz you don''t give it any type. Now your second question is confusing and I''m not sure if you phrased it correctly, so can''t answer. I think you "specialize" a template by doing this:
|
So now you can use "DillyDally" in place of "Dilly
This is how STL works. Everything is a template and most classes are typedef-ed versions of those templates.
Jinushaun
JinushaunNation Leprechaun
This is one of the things that's pretty easy to test yourself, I bet you'd get the answer at least 100 times faster if you just wrote a test program for it. Now that I tell you, can you really trust me
? Muahhahaha...errm.
C's typedefs aren't that powerful (unlike Ada's for instance), basically since C deploys a weak type-system. So the type-system will derive Dally to int and a declaration like:
will mean the same thing. Here's a small example program to play around with:
Testing yourself is (and will always be) the best way to learn!
Edited by - amag on March 9, 2001 4:16:28 AM
![](smile.gif)
C's typedefs aren't that powerful (unlike Ada's for instance), basically since C deploys a weak type-system. So the type-system will derive Dally to int and a declaration like:
|
will mean the same thing. Here's a small example program to play around with:
|
Testing yourself is (and will always be) the best way to learn!
Edited by - amag on March 9, 2001 4:16:28 AM
Thanks, that''s what I needed to know. I normally would have just tested this out, but I had to completely wipe my hard drive just recently, and I haven''t got a compiler right now. Gonna take a trip to Borland.com...
farmersckn
farmersckn
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement