Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Templates, Classes and unresolved symbols

Status
Not open for further replies.

mteichta

ISP
Feb 12, 2002
9
0
0
NL
Dear All,

I have the following

I have created a templated class defined as

template <class T> class Queue
{
public:
Queue();
~Queue();
Display();
};


this sits in templclasses.h

and the following in templclasses.cpp

#include &quot;stdafx.h&quot;
#include &quot;templclasses.h&quot;
#include <iostream>

template <class T> Queue<T>::Queue()
{}
template <class T> Queue<T>::~Queue()
{}
template <class T> Queue<T>::Display()
{}

I instansiate via

typedef Queue<data> Queue;
Queue Now;

when i try to link i get the following error
emplatesDlg.obj : error LNK2001: unresolved external symbol &quot;public: __thiscall Queue<struct data>::~Queue<struct data>(void)&quot; (??1?$Queue@Udata@@@@QAE@XZ)
templatesDlg.obj : error LNK2001: unresolved external symbol &quot;public: __thiscall Queue<struct data>::Queue<struct data>(void)&quot; (??0?$Queue@Udata@@@@QAE@XZ)

can anyone please assist ?
 
Put the implementation of the template method in the cpp
file, either after the class definition or inside it.
This should solve the problem
 
i have now moved all into the one header...i now have another problem

i have

template <class T> class Queue
{
public:
Queue() ;
~Queue() ;
void Display(int value);
};
template <class T> Queue<T>::Queue()
{
}
template <class T> Queue<T>::~Queue()
{
}
template <class T> void Queue<T>::Display(int value)
{
}

I instansiate with

typedef Queue<int> TItems;
TItems test;

when i call

test.Display(1);

i get

'Display' : function does not take 1 parameters

any help would be great
 
I do not know exactly what the reason might be for this bug, but try to do the following : Put the implementation inside the class definition:
template <class T> class Queue
{
public:
Queue() {};
~Queue() {};
void Display(int value){};
};

This might help.. Try to lose the typedef, it might cause problems, too
======
SeekerOfKnowledge
======
 
Ok..

i now have

template <class T> class Queue
{
public:
Queue() ;
~Queue() ;
void Display(int value){};
};

Queue<int> TItems;
int test=1;
TItems.Display(test);

SAME ERROR !!!

 
#include &quot;templclasses.h&quot;


template <class T> Queue<T>::Queue()
{}
template <class T> Queue<T>::~Queue()
{}
template <class T> void Queue<T>::Display(T &val)
{
fprintf(stderr,&quot;%d&quot;,val);
}
void main()
{
typedef Queue<int> Help;
Help test;
int val = 3;
test.Display(val);
}

This should solve your problem
 
hi

thanks for the input but this didnt solve the problem.

i implemented what you suggested and I recieved the same error.

the example you give shows how to pass a generic value, i need to pass both generic and specific parameters. For example

test.Display(data,1);

but i cant get the template to understand *ANY* parameters

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top