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

Why template<T> cannot make friend with T?

ben
template <typename T>
class A
{
friend class T; // error, but why?
};
Jul 23 '05 #1
4 1471
"ben" <be******@hotmail.com> wrote in message
news:42**********************@news.optusnet.com.au
template <typename T>
class A
{
friend class T; // error, but why?
};


Because the C++ standard says so.

http://groups-beta.google.com/group/...8a87917621b61e

Presumably allowing it to compile creates problems in some cases (or makes
the compiler harder to write), though I can't help with the details on this.
It may be noted that for some T the friend declaration would not make sense,
e.g., friend class int; This may (or may not) have some relevance.

--
John Carson

Jul 23 '05 #2
In article <d5**********@otis.netspace.net.au>,
"John Carson" <jc****************@netspace.net.au> wrote:
"ben" <be******@hotmail.com> wrote in message
news:42**********************@news.optusnet.com.au
template <typename T>
class A
{
friend class T; // error, but why?
};


Because the C++ standard says so.

http://groups-beta.google.com/group/...ead/fa2f0778df
c62abb/918a87917621b61e?q=May+a+template+argument+be+frie nds+of+the+template+c
lass+Malte+Starostik&rnum=1&hl=en#918a87917621b61e

Presumably allowing it to compile creates problems in some cases (or makes
the compiler harder to write), though I can't help with the details on this.
It may be noted that for some T the friend declaration would not make sense,
e.g., friend class int; This may (or may not) have some relevance.


Though there's a good chance that this will change in C++0X:

http://www.open-std.org/jtc1/sc22/wg...2004/n1722.pdf

-Howard
Jul 23 '05 #3
ben
Though there's a good chance that this will change in C++0X:


, which will be 10 years away???

ben
Jul 23 '05 #4
ben wrote:
Though there's a good chance that this will change in C++0X:


, which will be 10 years away???


.... and then for another 20 year you'll need to be compatible with the
current C++ Standard. Which is Not a Bad Thing, IMO: you can be sure
that C++ always means C++98.

::A::

Jul 23 '05 #5

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

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
4
by: Grey Plastic | last post by:
I have several classes that all keep track of static data. However, the manner that they keep track of static data is identical, and so I'm using the template<class Child> class Parent { ... };...
5
by: tuko | last post by:
The following snipet gives a linker error. I don't get it... template<class T> class tran { public: public: private: }; template<class T> class matrix {
5
by: Hendrik Schober | last post by:
Hi, I had originally suspected this to be a bug in the std lib, that's why I started a thred in the STL newsgroup. However, it seems as if it is a compiler bug, so I'm transfering it to here....
14
by: SoilMan | last post by:
Consider the following: class xyz { public: template <typename T> void foo(T x) { cout << "foo<T> " << x << endl; }
4
by: Gary li | last post by:
Hi, all I find "template template" class cann't been compiled in VC6 but can ok in Redhat9. I write a test program like as: template< template<class> class T> class A { }; int main() {...
4
by: Grizlyk | last post by:
Hello. Why were base class "typedefs" hidden by template<and explicit usage of them does not work too? Try open only one of the lines in the example below //using Tparent::Tptr; //typedef...
3
by: George2 | last post by:
Hello everyone, I sometimes saw code with template<and followed by a class definition, like, template<class { // class definition
10
by: jason.cipriani | last post by:
Is there any difference between declaring a template parameter as a "typename" or a "class"? E.g. template <class TT f() { } template <typename TT g() { } Thanks, Jason
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.