Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:31:39+00:00 2026-05-31T14:31:39+00:00

Is it possible to make the friend class a template, such as : template

  • 0

Is it possible to make the friend class a template, such as :

template <class T>
class MyClass {
public:
    friend class T;
};

The reason why I’m striving to get this is that I’m using policy-based design and I want my policy classes to access the host members.
(…now I begin to think that this might mean my design is simply bad… )

Thanks in advance guys!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:31:40+00:00Added an answer on May 31, 2026 at 2:31 pm

    In C++03 you are not allowed to declare friendship to an argument of the template.

    §7.1.5.3/2

    […] If the identifier resolves to a typedef- name or a template type-parameter, the elaborated-type-specifier is ill-formed. [Note: this implies that, within a class template with a template type-parameter T, the declaration

           friend class T;
    

    is ill-formed. ]

    In C++11 there has been some changes to this respect, but it is a bit weird. friend class T; is still illformed, but friend T is allowed. A quote can be found in the same paragraph:

    §7.1.5.3/2

    […] [ Note: This implies that, within a class template with a template type-parameter T, the declaration

     friend class T;
    

    is ill-formed. However, the similar declaration friend T; is allowed (11.3). — end note ]

    Notes are not normative, but they indicate the intent of the norms around it. I have not been able to find the specific sentence that makes the note correct, but I assume that at least the intention is that this should be allowed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: template<typename T> class Base { template<typename U> friend void f(void *ptr)
Is it possible to make a namespace friend of a class, say I have
Is it possible make some handler that will do something when user shutdown computer
Is it possible make an activity, that will lock the android device? That device
Is it possible to make a method return a dynamic List type. Such as
Is it possible to make a progressbar in Java like displayed on this page?
Is it possible to implement friend function and friend class (as in c++) in
I'm trying to compile such code: #include <iostream> using namespace std; class CPosition {
I have a base class which looks something like this: class Base { public:
I talked to a friend of mine and he told me that it's possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.