473,574 Members | 2,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(in t &)" (?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 2332
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(in t &)" (?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********@pobo x.com
Remove the 'g' from my address to send me mail.
Jul 19 '05 #2
"Russell Hanneken" <rg********@pob ox.com> wrote in message
news:j7******** *********@newsr ead4.news.pas.e arthlink.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(in t &)" (?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********@pobo x.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(doub le &r);

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

void funcDouble(doub le &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
1958
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 apply(func,seq): # # Code can default to # built-in definition in some cases: return __builtins__.apply(func,seq)
8
2063
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 invokation of g will return the interpreter's global namespace. Is there a way to do this and, if so, how? Muchas gracias for any and all assistance. Peace
25
3065
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 to/associated with? My understanding was that baz above belongs to some "default default namespace", but I have not been able to
3
10032
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" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/>...
7
7429
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 = {}; com.unFocus.Namespaces = new function() { this.register = function(namespace) { namespace = namespace.split('.');
6
2573
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 schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
5
2457
by: Mike Oliszewski | last post by:
Given the following c# code: namespace Company2 { public class SomeFunctions { public void FunctionA() { // Do Something. }
0
1283
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 getting several errors and not sure why or how to solve them does anyone have any help? How do I access the other file? ServerSocket.cs *This is...
5
14015
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 VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources......
14
3318
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
7835
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7753
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7847
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8132
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6500
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5645
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3769
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2265
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1365
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.