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

Link error when using Templates

P: n/a
I am using Visual Studio 2005 Beta1 and get the following errors when
building a .NET class library (called TryDLLPr in the example below). Any
advice on what's wrong will be greatly appreciated. The errors given are:

TryDLLPr.obj : error LNK2022: metadata operation failed (801311D6) :
Differing number of methods in duplicated types (TryInclude.AVect<int>):
LINK : fatal error LNK1255: link failed because of metadata errors

The following code, in the three files indicated, reproduces the errors.
Uncommenting the //a lines and deleting the corresponding lines do not give
any errors, indicating that the problem is related to my use of a template.
Also, uncommenting the //b lines and deleting corresponding lines in
"Included.h" and "Included.cpp" builds without error, but that route is not
attractive in my real applications.

#pragma once
#include "Included.h"
namespace TryDLLPr
{public ref class ClassX
{private: TryInclude::ClassY^ Y;
ClassX(){Y = gcnew TryInclude::ClassY;};
void Method(){Y->Method();};
#pragma once
namespace TryInclude
{template <class T> ref class AVect
int iSize;
void Append(T _TI){iSize++;};
//aref class AVectNT
//a int iSize;
//a public:
//a AVectNT(){iSize=0;};
//a void Append(int _TI){iSize++;};
public ref class ClassY
{AVect<int>^ IVectY;
//a AVectNT^ IVectY;
void Method();
//b ClassY(){IVectY = gcnew AVect<int>;};
//b void Method(){IVectY->Append(2);};
#include "StdAfx.h"
#include "Included.h"
{ IVectY = gcnew AVect<int>;
//a IVectY = gcnew AVectNT;
void TryInclude::ClassY::Method(){ IVectY->Append(2);}

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.