473,385 Members | 1,919 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.

friend declaration for template class

Hi, I have a class like so...

template<class XV, class T> class Foo {
Bar<T>* b;
};

and another class
template<class T> class Bar {
public:
friend template<class XV, class T> class Foo<XV,T>; // wrong
friend class Foo;
// wrong
friend class Foo<XV,T> //
wrong
};

so what is the correct way to give Foo access to Bar's members? Thanks..

Smith
Jul 19 '05 #1
2 17270
"john smith" <as**@asdf123asdf.net> wrote...
Hi, I have a class like so...

template<class XV, class T> class Foo {
Bar<T>* b;
};

and another class
template<class T> class Bar {
public:
friend template<class XV, class T> class Foo<XV,T>; // wrong
friend class Foo;
// wrong
friend class Foo<XV,T> // wrong
};

so what is the correct way to give Foo access to Bar's members? Thanks..


template<class XV, class U> friend class Foo;

Victor
Jul 19 '05 #2
"john smith" <as**@asdf123asdf.net> wrote...
Hi, I have a class like so...

template<class XV, class T> class Foo {
Bar<T>* b;
};

and another class
template<class T> class Bar {
public:
friend template<class XV, class T> class Foo<XV,T>; // wrong
friend class Foo;
// wrong
friend class Foo<XV,T> // wrong
};

so what is the correct way to give Foo access to Bar's members? Thanks..


template<class XV, class U> friend class Foo;

Victor
Jul 19 '05 #3

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

Similar topics

2
by: Christophe Barbe | last post by:
I am not clear about friend functions of a template class. GCC (3.3.2) wants me to add <> after the friend function names in the class declaration and VisualC++ doesn't like that. template...
2
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...
1
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...
5
by: Trevor Lango | last post by:
What is the appropriate syntax for placing a friend function that includes as one of it's parameters a pointer to the class object itself within the template class? I have the following: ...
2
by: Yu Lianqing | last post by:
Hi, all I am writing an overloading operator >> function for a template class and can't make it right. G++ 3.2 (Redhat8.0) gives the following errors: g++ -c list.cxx In file included from...
6
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...
2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
9
by: Adam Badura | last post by:
I have code like this template<int size> big_int { /* ... */ template<int size2> friend class big_int<size2>; }; What I wanted to achive is to be able to easly convert different sized...
4
by: fdmfdmfdm | last post by:
I have the following code: #include <iostream> #include <cstdlib> #include <cassert> using namespace std; template <class T> class Stack{ public: enum{DefaultStack = 10, EmptyStack = -1};
9
by: rtalbot | last post by:
I've got a container that looks like this: template <class T> class Foo { public: Foo() : _data(), _status(1) { } Foo(T) : _data(T), _status(0) { } ~Foo() { }
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...

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.