C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-26-2008, 06:11 AM   #1
The wheel reinvent0^r
 
hauzer's Avatar
 
Join Date: Aug 2008
Location: Србија
Posts: 115
Static libraries and template functions

Some of you may know the stack library I started developing for fun. I realized the C++ part was very poor so I decided to enchant it with template functions, I wrote them and everything compiled fine. The problem comes up when linking a project with the library (yes, I include the stack.hpp header), it says that there's no, for example, stack::push<int>(int) functions for linking but when I include the full source code it compiles&runs with no errors.
My question is how do I create static libraries with template functions?
hauzer is offline   Reply With Quote
Old 10-26-2008, 06:15 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
The entire template implementation needs to be in a header file when using templates.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 10-26-2008, 06:18 AM   #3
The wheel reinvent0^r
 
hauzer's Avatar
 
Join Date: Aug 2008
Location: Србија
Posts: 115
Ahh.. so there's no way..
hauzer is offline   Reply With Quote
Old 10-26-2008, 06:26 AM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Well, at least not if you:
1. Want to be able to compile it with most common compilers.
2. Do not want to write EVERY implementation that you could possibly conceive - this is really what prevents it from linking is that the way the templates work is that the code is generated as needed by the compiler. If you actually write
Code:
stack::push<int>(int) 
{
  ... // Code that pushes an integer onto a stack<int>
}
and every other stack operation for every other type that you use, then you could compile that into a librar that is not part of a header file.

But the whole point of using templates is generally that you do not WANT to write every variant of every function that you have templates for.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 10-26-2008, 06:28 AM   #5
The wheel reinvent0^r
 
hauzer's Avatar
 
Join Date: Aug 2008
Location: Србија
Posts: 115
Okay, thank you.
hauzer is offline   Reply With Quote
Reply

Tags
functions, library, problem, static library, templates

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error: template with C linkage michaels-r C++ Programming 3 05-17-2006 08:11 AM
im extreamly new help rigo305 C++ Programming 27 04-23-2004 11:22 PM
Prime Number Generator... Help !?!! Halo C++ Programming 9 10-20-2003 07:26 PM
include question Wanted420 C++ Programming 8 10-17-2003 03:49 AM
Borland, libraries, and template member functions roktsyntst C++ Programming 0 06-01-2003 09:52 PM


All times are GMT -6. The time now is 11:18 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22