473,473 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

template error.

3 New Member
I wrote a template class named "Class3". i also define a class "CNode" in class "Class3". all these code are written in file "mytemplate.h". when compiled, errors happens, just like:
testTemplate.obj : error LNK2001: unresolved external symbol "public: __thiscall Class3<int>::CNode::CNode(class Class3<int>::CNode *)" (??0CNode@?$Class3@H@@QAE@PAV01@@Z)
testTemplate.obj : error LNK2001: unresolved external symbol "public: __thiscall Class3<int>::CNode::~CNode(void)" (??1CNode@?$Class3@H@@QAE@XZ)
Debug/testTemplate.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

but when put constructor define of class "CNode" ,inside of declare of class "Class3",there are no errors. why?
template <class TYPE>
class Class3 : public CObject
{
public:
Class3();// Construction
virtual ~Class3();

class CNode
{
public:
CNode(CNode* pNodeParrent = NULL);
~CNode();
CNode* pParent;
CNode* pChild[10];
TYPE data;
};
};

template <class TYPE>
Class3<TYPE>::Class3()
{

}

template<class TYPE>
Class3<TYPE>::~Class3()
{


}

template<class TYPE>
Class3<TYPE>::CNode::CNode(CNode* pNodeParrent)
{
pParent = pNodeParrent;
for( int i=0; i<10; ++i) {
pChild[i] = NULL;
}
ZeroMemory(&data, sizeof(TYPE));

}
template<class TYPE>
Class3<TYPE>::CNode::~CNode()
{
pParent = NULL;
for( int i=0; i<10; ++i)
if( pChild[i]) {
delete pChild[i];
pChild[i] = NULL;
}

};
May 18 '06 #1
0 1311

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mat DeLong | last post by:
I have never been stuck on programming something before to the point I give up... this is a first. I am programming what should be something very easy in C++... using Templates. Here is the code,...
3
by: Chris | last post by:
I am having a very strange problem involving virtual functions in template classes. First of all, here is an extremely simplified structure of the two classes I am having problems with. ...
1
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following:...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
2
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of...
2
by: pagekb | last post by:
Hello, I'm having some difficulty compiling template classes as containers for other template objects. Specifically, I have a hierarchy of template classes that contain each other. Template...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
8
by: Jess | last post by:
Hi, I have a template function that triggered some compiler error. The abridged version of the class and function is: #include<memory> using namespace std; template <class T>
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.