472,350 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,350 software developers and data experts.

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;
}
Jul 22 '05 #1
3 1591
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

Jul 22 '05 #2
"Filipe Valepereiro" <ef***@portugalmail.pt> wrote in message
news:2f**************************@posting.google.c om...
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
Jul 22 '05 #3
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).

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Suzanne | last post by:
Hi++, I get a link error when I try to call a template function that is declared in a header file and defined in a non-header file. I do *not*...
1
by: Phil | last post by:
Ok, I have a template function for any pointer to type T: template <typename T> void func(T* p) { DoSomethingGeneric(p); } Can I specialize...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being...
6
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked...
3
by: moralbarometer | last post by:
Please i intend to make an XML document from a string using tranformer as shown below. It returns an error which trace is given below as well....
5
by: Mark | last post by:
Sorry for creating such a newbish topic, but I just can't seem to figure out what the problem is here. // main.cpp #include <cstdlib>...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of...
4
by: aaragon | last post by:
Hello all, I think the problem I'm facing is hard so I wonder if someone faced it before and if there is a simple solution to it. I am creating a...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.