 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Filipe Valepereiro Guest
|
Posted: Mon Sep 27, 2004 2:57 pm Post subject: Link error using pointers to functions with templates. |
|
|
I all.
I need to write a function that convert one string into a vector.
This string represent a serialized form of the vector.
So i come up with this piece of code, that compile just fine.
The problem is linking, VC6++ give me this error:
unresolved external symbol "class std::vector<double,class
std::allocator __cdecl VectorFromStr(class EFAString
&,double (__cdecl*)(class EFAString &))"
(?VectorFromStr@@YA?AV?$vector@NV?$allocator@N@std@@@std@@A
AVEFAString@@P6AN0@Z@Z)
My question is:
Can i pass pointers to template functions?
If i can't how can i circunvent this problem?
Thanks in advance
Filipe
/******** code here *********/
template <class T>
vector<T> VectorFromStr (string& str, T (*convertTo) (string&))
{
vector<T> v (0);
// skip first [vector=
char *data = strdup (str.data () + strlen ("[vector="));
// last ] becomes end of string
*(data + strlen (data) - 1) = 0;
T val;
char *p;
while (data) {
p = strstr (data, ",");
if (p) *p = 0;
v.push_back (convertTo (data));
// go to next value
data = p;
if (data)
data++;
}
return v;
}
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Mon Sep 27, 2004 3:06 pm Post subject: Re: Link error using pointers to functions with templates. |
|
|
Filipe Valepereiro wrote:
| Quote: | I need to write a function that convert one string into a vector.
This string represent a serialized form of the vector.
So i come up with this piece of code, that compile just fine.
|
The piece of code you posted is a template. Unless there is a bad
syntax error in it, there is no reason for the compiler not to let
it compile. What we need to see is the place where you _use_ that
function.
| Quote: | The problem is linking, VC6++ give me this error:
unresolved external symbol "class std::vector<double,class
std::allocator __cdecl VectorFromStr(class EFAString
&,double (__cdecl*)(class EFAString &))"
(?VectorFromStr@@YA?AV?$vector@NV?$allocator@N@std@@@std@@A
AVEFAString@@P6AN0@Z@Z)
My question is:
Can i pass pointers to template functions?
|
There is no such thing as pointers to template functions. Pointers
can only point to an instantiation of a template.
| Quote: | If i can't how can i circunvent this problem?
|
Perhaps you can post the complete code (without extraneous stuff
not related to the problem at hand).
V
|
|
| Back to top |
|
 |
David Hilsee Guest
|
Posted: Tue Sep 28, 2004 2:18 am Post subject: Re: Link error using pointers to functions with templates. |
|
|
"Filipe Valepereiro" <efann (AT) portugalmail (DOT) pt> wrote
| Quote: | I all.
I need to write a function that convert one string into a vector.
This string represent a serialized form of the vector.
So i come up with this piece of code, that compile just fine.
The problem is linking, VC6++ give me this error:
unresolved external symbol "class std::vector<double,class
std::allocator __cdecl VectorFromStr(class EFAString
&,double (__cdecl*)(class EFAString &))"
(?VectorFromStr@@YA?AV?$vector@NV?$allocator@N@std@@@std@@A
AVEFAString@@P6AN0@Z@Z)
My question is:
Can i pass pointers to template functions?
If i can't how can i circunvent this problem?
Thanks in advance
Filipe
/******** code here *********/
template <class T
vector
{
vector<T> v (0);
// skip first [vector=
char *data = strdup (str.data () + strlen ("[vector="));
// last ] becomes end of string
*(data + strlen (data) - 1) = 0;
T val;
char *p;
while (data) {
p = strstr (data, ",");
if (p) *p = 0;
v.push_back (convertTo (data));
// go to next value
data = p;
if (data)
data++;
}
return v;
}
|
I'm going to take a guess and say that this is answered in the FAQ
(http://www.parashift.com/c++-faq-lite/) Section 34 ("Container classes and
templates") question 12("Why can't I separate the definition of my templates
class from it's declaration and put it inside a .cpp file?") and byeond. If
that's not the problem, post more code (preferably somewhat complete).
--
David Hilsee
|
|
| Back to top |
|
 |
Filipe Valepereiro Guest
|
Posted: Tue Sep 28, 2004 9:44 am Post subject: Re: Link error using pointers to functions with templates. |
|
|
Thank's guy's.
It's the second time i fall in this error. I've defined the template
in the cpp file, and didn't notice that. No problem now, the code work
just fine :)
Thank's for the help ...
| Quote: | I'm going to take a guess and say that this is answered in the FAQ
(http://www.parashift.com/c++-faq-lite/) Section 34 ("Container classes and
templates") question 12("Why can't I separate the definition of my templates
class from it's declaration and put it inside a .cpp file?") and byeond. If
that's not the problem, post more code (preferably somewhat complete).
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|