473,837 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespaces, classes and template friend functions

hello,

i have problem with following code (see below). compiler (vs2005sp1)
complains
that the call to fn is ambiguous:
error C2668: 'BB::fn' : ambiguous call to overloaded function
could be 'void BB::fn<dummy>(T &,BB::foo &)'
or 'void AA::fn<dummy>(T &,BB::foo &)'

okay, i have said, and tried to be more specific about the namespace
the fn<lives in, i.e. from
template<class Tfriend void fn(T &, foo &);
to
template<class Tfriend void AA::fn(T &, foo &);

wow:
void AA::fn(T &,BB::foo &)' : symbol cannot be defined within
namespace 'BB'
defined? who? where? i merely declared the function to be friend, no?

best regards,
mojmir
=8<============ =============== =============== =========

namespace BB {
class foo;
}

namespace AA {
template<class Tvoid fn(T &, BB::foo &);
}

namespace BB {
class foo {
template<class Tfriend void fn(T &, foo &);
};
}

namespace AA {
template<class Tvoid fn (T &, BB::foo &) { }
}

class dummy { };

void wmain() {
using namespace BB;
using namespace AA;
foo f;
dummy d;
fn(d, f);
}
Sep 12 '08 #1
3 1727
mojmir wrote:
hello,

i have problem with following code (see below). compiler (vs2005sp1)
complains
that the call to fn is ambiguous:
error C2668: 'BB::fn' : ambiguous call to overloaded function
could be 'void BB::fn<dummy>(T &,BB::foo &)'
or 'void AA::fn<dummy>(T &,BB::foo &)'

okay, i have said, and tried to be more specific about the namespace
the fn<lives in, i.e. from
template<class Tfriend void fn(T &, foo &);
to
template<class Tfriend void AA::fn(T &, foo &);
ehm, I guess the error refers to the call
fn(d, f);
that should be
AA::fn(d, f);

Best wishes,

Zeppe
Sep 12 '08 #2
Zeppe wrote:
mojmir wrote:
>hello,

i have problem with following code (see below). compiler (vs2005sp1)
complains
that the call to fn is ambiguous:
error C2668: 'BB::fn' : ambiguous call to overloaded function
could be 'void BB::fn<dummy>(T &,BB::foo &)'
or 'void AA::fn<dummy>(T &,BB::foo &)'

okay, i have said, and tried to be more specific about the namespace
the fn<lives in, i.e. from
template<cla ss Tfriend void fn(T &, foo &);
to
template<cla ss Tfriend void AA::fn(T &, foo &);

ehm, I guess the error refers to the call
My bad, I didn't pay attention before answering. I guess the problem is
that the friend template function declaration is a template declaration,
and you cannot declare a function as belonging to a different namespace.
Unfortunately, when you specify a friend template function I don't think
there is any way to avoid making a template declaration, so I don't know
how to solve the problem (if it can be).

Best wishes,

Zeppe
Sep 12 '08 #3
On Sep 12, 11:28 am, Zeppe
<ze...@remove.a ll.this.long.co mment.yahoo.itw rote:
Zeppe wrote:

there is any way to avoid making a template declaration, so I don't know
how to solve the problem (if it can be).
well fortunately in my case i can simply move the AA::fn into
namespace BB
thus removing ambiguity, but i wonder whether 'dragging' the function
fn as
injected friend into BB's namespace is correct.

mojmir
Sep 12 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10168
by: Christophe Barbe | last post by:
I posted a few days ago about the same problem but was not very clear. So here is my second take at it. Basically with GCC 3.3.2, I can't compile the example from the C++ FAQ Lite available online at http://www.parashift.com/c++-faq-lite/containers-and-templates.html#faq-34.15 Below are the two files that I compile with g++ foo.cpp -o foo or
1
4451
by: Dmitry D | last post by:
Hi all, I'm having problems with declaring a template friend function. It seems like I've done everything as explained in C++ FAQ, but still, I'm getting the linker error (unresolved external 'aFunc(A<char> const&)' ) in the following sample program. Tried it on GCC and Borland's compiler. Can somebody please show me the correct way to fix this? Thanks, Dmitry
6
2344
by: Adam Parkin | last post by:
Hello, all I'm having a problem with friend functions in a templatized Queue class I'm writing using linked lists. The problem is that I can't get the friend function to be able to access private data from the class. Here's the gist of the code: template <class T> struct NodeType { T data; NodeType<T> * link;
5
2648
by: Ruben Campos | last post by:
Some questions about this code: template <typename T> class MyTemplate; template <typename T> MyTemplate <T> operator- (const MyTemplate <T> & object); template <typename T> MyTemplate <T> operator- (const MyTemplate <T> & object1, const MyTemplate <T> & object2); template <typename T> class MyTemplate
3
1598
by: jason | last post by:
Please pardon my completely lack of understanding on the topic. I have a website I developed with another developer. We are both far from experts in VB.NET and OOP. We developed the site WITHOUT VS.NET, compiling vb.net code into a common dll in the bin directory off the root of the website. That one vb code creates a namespace we import in all of our ASP.NET code. Compiling was done fromt he command line use vbc.exec. The site works...
3
1490
by: Pierre Barbier de Reuille | last post by:
Hi, after reading the article " The Standard Librarian : Defining Iterators and Const Iterators" from Matt Austern: http://www.ddj.com/showArticle.jhtml;jsessionid=41JODBZDWEMBYQSNDLOSKH0CJUNN2JVN?articleID=184401331 I wanted to test using the non-template function friends of template classes. So I devised this code: ===8<======8<======8<======8<======8<======8<======8<===
1
2054
by: curious2007 | last post by:
Hello everybody, When I try to declare nontemplate friend functions I get the following warning: friend decleration......declares a non-template function (if this is not what you intended, make sure the function tempate has already been declared and add<> after the function name here)-Wno-non-template-friend disables this warning. Since declaring a non-template friend function is what i have intended, I would like to disable this...
3
2484
by: Rahul | last post by:
Hi Everyone, The following code works fine, class A { private: friend void sample(A& obj) { printf("in friend...\n"); printf("%d",obj.i);
21
4758
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code that gets the same result) works as expected in visualc++. I know that this is probably not the right behavior for a compiler but it's the kind of behavior I'm searching for so I was hoping there was a way to do the same thing in gcc. As you know...
1
10628
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
10275
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9406
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
7807
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
7004
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
5670
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5850
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4475
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
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.