F
Filipe Valepereiro
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 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;
}