Jump to content
  • Advertisement
Sign in to follow this  
jolyqr

Visual C++ 2005 Express Edition

This topic is 4500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to compile a class template, but it seems like the compilater does not like these type of classes. Basically, when I compile the class, without using any template instructions, the compilation does work, buy using the template instructions, it does not. the compiler gives me the following errors:

Share this post


Link to post
Share on other sites
Advertisement

------ Build started: Project: TemplateSample, Configuration: Debug Win32 ------
Compiling...
FileManagement.cpp
Linking...
TemplateSample.obj : error LNK2019: unresolved external symbol "public: __thiscall myFileManagement::FileManagement<int>::~FileManagement<int>(void)" (??1?$FileManagement@H@myFileManagement@@QAE@XZ) referenced in function _wmain
TemplateSample.obj : error LNK2019: unresolved external symbol "public: __thiscall myFileManagement::FileManagement<int>::FileManagement<int>(void)" (??0?$FileManagement@H@myFileManagement@@QAE@XZ) referenced in function _wmain
C:\Documents and Settings\Joly\Bureau\TemplateSample\Debug\TemplateSample.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Joly\Bureau\TemplateSample\TemplateSample\Debug\BuildLog.htm"
TemplateSample - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
[source langu="c++"]
#pragma once

namespace myFileManagement
{
template <typename T>
class FileManagement
{
public:
FileManagement(void);
void Print(T);
public:
~FileManagement(void);
};
}

Share this post


Link to post
Share on other sites
[source langu="c++"]
#include "StdAfx.h"
#include "FileManagement.h"
#include <iostream.h>

namespace myFileManagement
{
template <typename T>
FileManagement<T>::FileManagement(void)
{
}

template <typename T>
FileManagement<T>::~FileManagement(void)
{
}

template <typename T>
void FileManagement<T>::Print(T val )
{
cout<<val;
}
}


Share this post


Link to post
Share on other sites
here is an example of the using of the class:


// TemplateSample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cstdio>
#include "FileManagement.h"

int _tmain(int argc, _TCHAR* argv[])
{
myFileManagement::FileManagement<int> p;
p.Print(1);
getchar();
return 0;
}

Share this post


Link to post
Share on other sites
Try not seperating your implementation from your definition. Everything should just go in the Header File.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Move the implementation into the header files. This is a problem specific to templates. So:


#pragma once

namespace myFileManagement
{
template
class FileManagement
{
public:
FileManagement(void);
void Print(T);
public:
~FileManagement(void);
};
}


becomes


#pragma once

namespace myFileManagement
{
template class FileManagement
{
public:
FileManagement(void) {}
~FileManagement(void) {}

void Print(T val)
{
cout <

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Wow yeah, this board sucks with posting code, but that should give you the idea.

Share this post


Link to post
Share on other sites
Quote:

the compiler gives me the following errors:

Uh? I see no errors. Oh, wait...
Quote:

------ Build started: Project: TemplateSample, Configuration: Debug Win32 ------
Compiling...
...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Yeah, there are some errors. But no question. Wait, there is some otehr infos:
Quote:

here is my class

?
There is no class here! You forgot to paste the code!
No, I'm wrong, it is in the next post again:
Quote:

(some code)

And in the next post
Quote:

(some code)

And in the next post too
Quote:

here is an example of the using of the class:
(some code)

...
Still, no question, but everyone is understanding what you really need: you want to get rid of your compiler errors. Hence the answers of Adam and the AP (both correct).

But it is not my point.

jolyqr, it would be very nice if you stop cutting what is really a single question into many posts (6 ?!?!). Or will you continue to use this uberstyley style, even if you need to cut up you posts in words and send a word at a time?

I have pretty some good news for you: we don't mind reading long posts, and the law don't enforce a regular use of the send button. Quite good, isn't it?

Regards,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!