Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have found your site brilliant. What makes it good are the people that contribute to the site..."

Geography

Where in the world do Tek-Tips members come from?
isaisa (Programmer)
8 Dec 06 3:48
Hi all,
  Following are some doubts regarding templates

1. When i say that the template is instatiating, i need the concrete type to instantiate the template. i am not clear on this as to what types i refer to be concrete. Extending this when i have the following code

CODE

   //File.h
   template <typename T>
     void foo(T temp) {
        // some code here
     }
   
   //FileMain.cpp
   int i = 40;
   int *ptr = &i;
   foo(ptr);
   
  
  In the code snippet above, does the statement means that the pointer type is also the concrete type ????

2. it is said that the template functions have external linkage normally. what is the reason behind this ?
   

thanks in advance

sanjay
isaisa (Programmer)
8 Dec 06 6:45
hi all
  wnated add some more doubts in the last post as follows

3. while overloading the template function, the template parameters are not taken in to consideration as per my understanding. what is the reason behind this ? The difference in the template parameters represents the different set of function families. Am i correct on thinking ?


4. Function temeplates and the template classes internally generates the version for after specialization happens or rather instantiation happens for specific data types. In case of class templates, how class with the same names but for different data types are maintained in the system? [assuming the instantiation happens in the same translation unit in the same namespace scope].

Regards
sanjay
ArkM (IS/IT--Management)
8 Dec 06 7:29
1.

Quote (C++ Standard, 14.1):

There is no semantic difference between class and typename in a template-parameter.
But class and typename keywords are not aliases in other contexts!
T is a type in your snippet: int, int*, int&, your classes etc are types. Template parametes are types or non-types (for example, int i).

2. Normally, as usually - that's all. You may define template function with internal linkage, of course (with static keyword - but what for?). See also:
[quote C++ Standard 1.4 Implementation compliance.
The templates, classes, functions, and objects in the library have external linkage.
[/quote]
It's about C++ Standard Library templates...
cpjust (Programmer)
8 Dec 06 11:08
1.  A concrete type is a non-template, i.e. something that you can create as a variable like:  int num;

The following would not compile:  vector<list> blah;  because list is also a template and needs a type specified.  So to turn the list into a concrete type, so that vector also has a concrete type, you can do this:  vector<list<int> > blah;

2.  I have no idea.

3.  Could you give an example?  I'm not exactly sure what you're asking there.

4.  Class templates do have different names, because you have to specify a type along with it.  Ex.

CODE

vector<int>  intArray;
vector<char> charArray;
isaisa (Programmer)
9 Dec 06 3:48
hi
   Thank all for clarifying my doubts.

 cpjust, i got the answer in your question for point no 3. My question was wrong ...thanks for the help anyway ....


Sanjay

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close