![]() |
|
#1
|
|||
|
|||
About template functionsTemplate classes has to be coded only in the header files. Does this rule apply to template functions?
One example i can think of is that it is being used as a static function. Meaning its being use by another function define in the header file. CPP / C++ / C Code:
CPP / C++ / C Code:
If the static function is not being used, will it still be compiled into obj file? I know it sounds stupid, but i think it wouldn't cause T is not being specified. |
|||
|
#2
|
|||
|
|||
Re: about template functions.Quote:
The template of a templated function must be known to the compiler wherever you use it (usually you do this by putting the template definition in a header file). CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Compiled with: Code:
Output is: Code:
Note that the main() function doesn't know or care that a templated function is used; it only needs to know the signature of MyFunc. Since MyFunc uses the templated function in its implementation, the template must be known to the compiler when myfunc.cpp is compiled. Regards, Dave Footnote: Your use of the word "static" is inappropriate for this discussion. I think you mean "non-templated function" or some such thing. The keyword "static" has a specific meaning unrelated to this topic. |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ Graph Representation Problem | Peter_APIIT | C++ Forum | 1 | 15-Jan-2009 06:14 |
| Tree container | kawafis44 | C++ Forum | 1 | 24-Oct-2008 01:53 |
| Need help implementing a stack with linked lists | michael.wesolow | C++ Forum | 4 | 10-Oct-2008 16:45 |
| Fatal error C1083: Cannot open include file | mia | C++ Forum | 5 | 14-May-2007 15:35 |
| Template usage - global functions | ankakusu | C++ Forum | 3 | 18-Dec-2006 15:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The