473,387 Members | 3,787 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,387 software developers and data experts.

Linker error with template function

Hi,
I'm using MS VS.Net2003, and I'm getting a linker error in a project for a
templated friend function

Specifically:

template <class Tclass Vec3

{...

friend Vec3<Toperator -( const Vec3<T>& v );

};

Then later I have defined:

template <class Tinline Vec3<Toperator -(const Vec3<T>& v)

{

return Vec3<T>( -v.n[0], -v.n[1], -v.n[2] );

}

and explicitly instantiated:

typedef Vec3<doubleVec3d;

But, then I get a linker error:

error LNK2019: unresolved external symbol "class Vec3<double__cdecl
operator-(class Vec3<doubleconst &)" (??G@YA?AV?$Vec3@N@@ABV0@@Z)
referenced in function "bool __cdecl pointToTriDist(class Vec3<double>,class
Vec3<double*,double,double &,class Vec3<double&,class Vec3<double&,int
*)" (?pointToTriDist@@YA_NV?$Vec3@N@@PAV1@NAANAAV1@3PA H@Z)
This happens for all the templated friend functions (global) defined in the
template classes. What is the cause for this ? How can I fix this ?

Thanks,

-g


Nov 21 '06 #1
1 2087

giganut wrote:
Hi,
I'm using MS VS.Net2003, and I'm getting a linker error in a project for a
templated friend function

Specifically:

template <class Tclass Vec3

{...

friend Vec3<Toperator -( const Vec3<T>& v );

};

Then later I have defined:

template <class Tinline Vec3<Toperator -(const Vec3<T>& v)

{

return Vec3<T>( -v.n[0], -v.n[1], -v.n[2] );

}

and explicitly instantiated:

typedef Vec3<doubleVec3d;

But, then I get a linker error:

error LNK2019: unresolved external symbol "class Vec3<double__cdecl
operator-(class Vec3<doubleconst &)" (??G@YA?AV?$Vec3@N@@ABV0@@Z)
referenced in function "bool __cdecl pointToTriDist(class Vec3<double>,class
Vec3<double*,double,double &,class Vec3<double&,class Vec3<double&,int
*)" (?pointToTriDist@@YA_NV?$Vec3@N@@PAV1@NAANAAV1@3PA H@Z)
This happens for all the templated friend functions (global) defined in the
template classes. What is the cause for this ? How can I fix this ?

Thanks,

-g
this is discussed many times before...check out the FAQ...
http://www.parashift.com/c++-faq-lit...html#faq-35.16

Nov 21 '06 #2

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

Similar topics

10
by: william xuuu | last post by:
Actually, I also got linker errors with template functions and template classes. And I avoided both of them successfully, by pouring foo.cpp into foo.h, according to the C++ FAQ. ...
2
by: haplotype | last post by:
I have designed a package with several files, which is listed bellow base.cpp & base.hpp - define the template class base tree.cpp & tree.hpp - define the class tree derived from base<int>...
3
by: Bob Altman | last post by:
Hi all, This is the first time I've tried to create a templatized function, and I can't get past a linker error. I create a new, unmanaged C++ application and added a class named MyClass. In...
0
by: Robbie Hatley | last post by:
I'd always thougth that a C++ compiler/linker should be able to instantiate a template in mulitple places (say, in two different translation units), even using the same template parameters so that...
2
by: Robbie Hatley | last post by:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote: > Robbie Hatley wrote: > > > > I ran into a problem a few days ago when I added a couple of > > template functions to one of my personal...
1
by: toton | last post by:
In C++ , when the class is declared in the header & not implemented in the cpp, the linker is not giving a error untill the method gets called. How to ensure that all non pure-virtual method...
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...
7
by: meLlamanJefe | last post by:
The following is an abridged copy of the code I am using in a template function along with the linker error produced during the build. The compiler has no issues with the code, only the linker: ...
1
bajajv
by: bajajv | last post by:
Hi, While implementing CList class, I got linker errors for constructor and destructor. Below is the code - template<class TYPE, class ARG_TYPE = const TYPE&> class CList { protected: struct...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.