|
-
February 26th, 2003, 08:59 AM
#1
Using a template function as for_each "argument" = unresolved external symbol error
Hello,
I tried to make the subject intuitive. Anyway, as described, I'm
trying to use a template function as the function argument for
for_each(). In particular, I'm trying to use boost's checked_delete
in an attempt to basically delete every member in a vector of
pointers [who each point to dynamically allocated memory].
Yeah, I know I could just do a loop and delete each one explicitly,
but I was kind of wanting to save a little space 
Anyway, I'm getting an "unresolved external symbol" error ... and
rightly so. Just telling for_each() to CALL this template function
doesn't actually instantiate it. I've found that to use this function
as a functor, I have to do something like this first [for every
type that I want to use checked_delete with]:
Code:
checked_delete<SomeType>(0);
This will instantiate the proper function and everything works
great [albeit with one additional line of code].
So, my question: is there a better way to achieve my goal of using
a template function as a function argument to for_each()?
Here's basically what my for_each line is:
Code:
for_each(container.begin(), container.end(), boost::checked_delete<SomeType>);
If you're not familiar with boost, checked_delete is a "safer"
delete. The only reason I'm using it is that it won't really cost me
anything ... and it's an existing function that'll delete for me so
I don't need to write my own....
Thank you for your time.
--Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|