473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2320
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Blair Hall | last post by:
Can anyone please tell me how to correctly use a built in function when there is a function of the same name in local scope? Here is an example. Suppose the following is in myApply.py: def...
8
by: Elaine Jackson | last post by:
I would like to be able to write a function f, which will live in a module M, and will call a function g, such that, when f is imported from M into the interpreter, and invoked there, its...
25
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
5
by: Mike Oliszewski | last post by:
Given the following c# code: namespace Company2 { public class SomeFunctions { public void FunctionA() { // Do Something. }
0
by: Tressa | last post by:
Sorry to be such a novice about this but..... I have a windows service. It contains two separate files. Both have the same namespace name. I need to pass "bDisplay" into the other file. I am...
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
14
by: Tiraman | last post by:
Hi , I would like to use nested namespace . I have 3 namespace as dll's : Namespace A Namespace B Namespace C And i want to have some namespace that contain them all , some thing like
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.