469,631 Members | 1,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

namespace help

file: prog1.cpp
#include <stdio.h>
#include "temp1.h"

int main()
{
double d;
Templ1::func(d);
return 0;
}

file: temp1.h
namespace Templ1
{
template <class T> void func(T &);
}

file:temp1.cpp
namespace Templ1
{
template <class T> void func(T &i)
{
i = 0;
}
}

When I compile using VC, I get:
Linking...
prog1.obj : error LNK2001: unresolved external symbol "void __cdecl
Templ1::func(int &)" (?func@Templ1@@YAXAAH@Z)
Debug/prog1.exe : fatal error LNK1120: 1 unresolved externals

How can I still use templated version func() from different module (temp1.*)

Regards,
Elias
Jul 19 '05 #1
3 2203
lallous wrote:
file: temp1.h
namespace Templ1
{
template <class T> void func(T &);
}

file:temp1.cpp
namespace Templ1
{
template <class T> void func(T &i)
{
i = 0;
}
}

When I compile using VC, I get:
Linking...
prog1.obj : error LNK2001: unresolved external symbol "void __cdecl
Templ1::func(int &)" (?func@Templ1@@YAXAAH@Z)
Debug/prog1.exe : fatal error LNK1120: 1 unresolved externals

How can I still use templated version func() from different module
(temp1.*)


Check the FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-34.12

Regards,

Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Jul 19 '05 #2
"Russell Hanneken" <rg********@pobox.com> wrote in message
news:j7*****************@newsread4.news.pas.earthl ink.net...
lallous wrote:
file: temp1.h
namespace Templ1
{
template <class T> void func(T &);
}

file:temp1.cpp
namespace Templ1
{
template <class T> void func(T &i)
{
i = 0;
}
}

When I compile using VC, I get:
Linking...
prog1.obj : error LNK2001: unresolved external symbol "void __cdecl
Templ1::func(int &)" (?func@Templ1@@YAXAAH@Z)
Debug/prog1.exe : fatal error LNK1120: 1 unresolved externals

How can I still use templated version func() from different module
(temp1.*)
Check the FAQ:

http://www.parashift.com/c++-faq-lit....html#faq-34.1
2
Regards,

Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.

Hello,
So I understand that I must say: #include "temp1.cpp" instead of ".h" (or
move implementation into header file) ?

What alternative do you suggest, even if I have to redesign my code...
I want to use templates and namespace...

Currently, I put in header file different version of func() as:
funcInt(int &r);
funcDouble(double &r);

then in cpp file I put:
void funcInt(int &i)
{
func(i);
}

void funcDouble(double &i)
{
func(i);
}
Regards,
Elias
Jul 19 '05 #3
lallous wrote:
So I understand that I must say: #include "temp1.cpp" instead of ".h"
(or move implementation into header file) ?


or #include the .cpp file at the end of the header.

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Blair Hall | last post: by
8 posts views Thread by Elaine Jackson | last post: by
25 posts views Thread by kj | last post: by
3 posts views Thread by Mike Dickens | last post: by
7 posts views Thread by Kevin Newman | last post: by
5 posts views Thread by Mike Oliszewski | last post: by
14 posts views Thread by Tiraman | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.