Link error using pointers to functions with templates.



 DEVELOP > c-Plus-Plus > Link error using pointers to functions with templates.

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER