| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Filipe Valepereiro" |
| Date: |
27 Sep 2004 09:57:19 AM |
| Object: |
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<double> > __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;
}
.
|
|
| User: "David Hilsee" |
|
| Title: Re: Link error using pointers to functions with templates. |
27 Sep 2004 09:18:50 PM |
|
|
"Filipe Valepereiro" <efann@portugalmail.pt> wrote in message
news:2f0e0afd.0409270657.390029bb@posting.google.com...
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<double> > __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;
}
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
.
|
|
|
| User: "Filipe Valepereiro" |
|
| Title: Re: Link error using pointers to functions with templates. |
28 Sep 2004 04:44:59 AM |
|
|
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 ...
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).
.
|
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Link error using pointers to functions with templates. |
27 Sep 2004 10:06:38 AM |
|
|
Filipe Valepereiro wrote:
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.
The problem is linking, VC6++ give me this error:
unresolved external symbol "class std::vector<double,class
std::allocator<double> > __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.
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
.
|
|
|
|

|
Related Articles |
|
|