473,804 Members | 3,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<dou ble,class
std::allocator< double> > __cdecl VectorFromStr(c lass EFAString
&,double (__cdecl*)(clas s EFAString &))"
(?VectorFromStr @@YA?AV?$vector @NV?$allocator@ N@std@@@std@@A
AVEFAString@@P6 AN0@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 1684
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<dou ble,class
std::allocator< double> > __cdecl VectorFromStr(c lass EFAString
&,double (__cdecl*)(clas s EFAString &))"
(?VectorFromStr @@YA?AV?$vector @NV?$allocator@ N@std@@@std@@A
AVEFAString@@P6 AN0@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***@portugal mail.pt> wrote in message
news:2f******** *************** ***@posting.goo gle.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<dou ble,class
std::allocator< double> > __cdecl VectorFromStr(c lass EFAString
&,double (__cdecl*)(clas s EFAString &))"
(?VectorFromStr @@YA?AV?$vector @NV?$allocator@ N@std@@@std@@A
AVEFAString@@P6 AN0@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
11540
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 function directly in the header file, or if the change the function to non-template. For example... *** Why am I getting a link error for template function f() in the code below?
1
2837
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 pointers to member functions, or pointers to anything)? I would like to do
16
16295
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
4765
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 appreciated. Thanks in advance
6
2944
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 calling Mesh class functions. Let's say they point to each other like this: class Vertex { HalfEdge *edge; }; class HalfEdge { Vertex* vert;
3
1713
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() { try { javax.xml.transform.dom.DOMResult domresult=new
5
2670
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 std;
18
2884
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 write an ordinary differential equation class that would solve a general equation in the form: dx/dt = f(x,t). The ode class shouldn't know anything about f, except how to call it.
4
2031
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 information at runtime after reading a file. After reading the file, several objects of a templated ClassA are created. I thought that the way to do this is to create an abstract class AbstractClassA and have all templated classes inherit from the...
0
9707
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.