473,738 Members | 10,643 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 2339
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
1965
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
2074
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
3090
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
10043
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"/> <xsl:template match="/">
7
7438
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
2588
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
2463
by: Mike Oliszewski | last post by:
Given the following c# code: namespace Company2 { public class SomeFunctions { public void FunctionA() { // Do Something. }
0
1301
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 where the main server start is so the" private bool m_bIsDisplayed = false;" had to go here so it...
5
14036
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... Updating references...
14
3332
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
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8210
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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
2
2745
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.