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

G

Guest

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 --------
 
D

David Lowndes

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:
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
 
D

David Lowndes

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top