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 935371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:08:47+00:00 2026-05-15T21:08:47+00:00

please consider the following code: template <typename T> struct foo { template <typename S>

  • 0

please consider the following code:

template <typename T>
struct foo
{
    template <typename S>
    struct bar
    {
        template <typename> friend struct bar;
    };
};

I’d like all instantiations of foo<T>::bar to be friends of foo<T>::bar<S> for any S. If bar is not a nested template, the syntax above works just fine. But when I do for example

int main() 
{  
    foo<int> x;
}

MSVC8 (Visual C++ 2005) doesn’t like it:

1>.\main.cpp(11) : error C3855: 'foo<T>::bar': template parameter 'S' is incompatible with the declaration
1>        .\main.cpp(12) : see reference to class template instantiation 'foo<T>::bar<S>' being compiled
1>        .\main.cpp(14) : see reference to class template instantiation 'foo<T>' being compiled

The compiler gives me the same errors if I use

template <typename> friend struct foo<T>::bar;

instead. How can I achieve what I want ?

EDIT: I double checked (it’s morning here, and I’m not really awake), this seems to be a VC8 bug:

  • 1 1 Answer
  • 1 View
  • 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-15T21:08:48+00:00Added an answer on May 15, 2026 at 9:08 pm

    All restrictions for friend of a class or class template are described in section 14.5.3 of the C++ Standard. Your code is valid. Check you have installed all latest service packs for the Visual Studio. Here you can find related bugs in Visual Studio.

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

Sidebar

Related Questions

Please consider the following code. struct foo { }; template<typename T> class test {
Please consider the following code, struct foo { foo() { std::cout << Constructing! <<
Please consider the following code: #include <iostream> #include <typeinfo> template< typename Type > void
Consider the following code: struct Foo { mutable int m; template<int Foo::* member> void
Consider the following code template<typename T, int N> struct A { typedef T value_type;
Please consider the following code: typedef struct { int type; } object_t; typedef struct
please consider the following code: typedef struct Person* PersonRef; struct Person { int age;
Please consider the following code: float float_value = x; // x is any valid
Please consider the following code. enum type {CONS, ATOM, FUNC, LAMBDA}; typedef struct{ enum
Consider the following code: #include <iostream> class Bar { public: void foo(bool b =

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.