By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

error LNK2019: unresolved external symbol with Studio.NET 2003!

P: n/a
Hi, All
I am migrating to Studio .NET 2003 from Studio 6.0 and Studio .NET 2002. When I compiled my code, which is compilable both in VC++ 6.0 and Studio .NET 2002, I have an error LNK2019 as the following

-------------------------------------------------------------------------
error LNK2019: unresolved external symbol "class CPV3<double> __cdecl operator*(double,class CPV3<double> const &)" (??D@YA?AV?$CPV3@N@@NABV0@@Z) referenced in function _mai
-------------------------------------------------------------------------

The error is related to a template function! Does any body have any idea to solve this problem

#include "stdafx.h
#include "PV3.h

int _tmain(int argc, _TCHAR* argv[]

CPV3<double> aVec, bVec

aVec.x = 1.0
aVec.y = 2.0
aVec.z = 3.0

bVec.x = 2.0
bVec.y = 2.0
bVec.z = 2.0

aVec = 2.0*bVec; // error LNK2019: unresolved external symbol

Swap(bVec,aVec); // this function works wel
return 0
// -------------------------------
// file "PV.h

template< class T
class CPV

// Attribute
public
/
unio

struc

T x
T y
T z
}
}
// Method
public
CPV3()
~CPV3()
friend CPV3<T> operator * ( const double dMul, const CPV3<T>& a )
friend void Swap( const CPV3<T>& a, const CPV3<T>& b )
}

template< class T
CPV3<T>::CPV3(

template< class T
CPV3<T>::~CPV3(

template< class T
CPV3<T> operator * ( const double dMul, const CPV3<T>& a

CPV3<T> pv( a )

pv.x *= dMul; pv.y *= dMul; pv.z *= dMul

return pv
template< class T
void Swap( CPV3<T>& a, CPV3<T>& b

CPV3<T> tmp(a)

a = b
b = tmp

// ------ end of file PV.h --------

// --------------------------------
// File PV.cp
#include "stdafx.h
#include "PV3.h

template class CPV3< double >

template CPV3<double> operator * ( const double dMul
const CPV3<double>& a )
template void Swap( CPV3<double>& a, CPV3<double>& b )

// ------- Enf of file PV.cpp --------
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>I am migrating to Studio .NET 2003 from Studio 6.0 and Studio .NET 2002. When I compiled my code, which is compilable both in VC++ 6.0 and Studio .NET 2002, I have an error LNK2019 as the following:

--------------------------------------------------------------------------
error LNK2019: unresolved external symbol "class CPV3<double> __cdecl operator*(double,class CPV3<double> const &)" (??D@YA?AV?$CPV3@N@@NABV0@@Z) referenced in function _main
--------------------------------------------------------------------------

The error is related to a template function! Does any body have any idea to solve this problem!


I can also reproduce your problem with VS2003 and the VS2005 preview
compiler, and as it builds and runs fine with VC6, it would appear to
be a bug or some obscure C++-ism I'm not aware of. Since it looks like
a bug to me, I'll try to pass it on to MS.

I'm afraid I don't have a suggested work-around, so unless someone
else has an idea, I suggest that you phone MS PSS and see what they
have to say about it.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #2

P: n/a
>I can also reproduce your problem with VS2003 and the VS2005 preview
compiler, and as it builds and runs fine with VC6, it would appear to
be a bug or some obscure C++-ism I'm not aware of.


It turns out to be a subtle C++-ism.

If you change the friend declaration to this:

template< class U >
friend CPV3 operator* ( const double dMul, const CPV3 & a );

it'll compile and work fine.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #3

P: n/a
Hi, David

I have figured out that adding template <class T> in front of friend is enough, no other changes are necessary!

My program works well wit

template <class T> friend CPV3<T> operator * ( const double dMul, const CPV3<T>& a )

Just let you know! Thank you again

Ya

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.