473,412 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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 1651
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* get this link error if I define the template...
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 this template for pointers to functions (or...
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 info about ]
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 executed when an error occurs. Any help would be much...
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 properly in the process of building up the mesh by...
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. please help. public org.w3c.dom.Node getTextXML()...
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> #include <iostream> #include "Vector.h" using namespace...
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 another class. Specifically, I am trying to...
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 program that basically takes all the required...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.