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

  • Home
  • SEARCH
  • 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 6019559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:26:21+00:00 2026-05-23T03:26:21+00:00

I am writing a small class, the class is basically a factory for the

  • 0

I am writing a small class, the class is basically a factory for the C class, but I want other classes to be able to access some of the methods.

template<class C>
class CFactory {
public:   
   friend class C;
};

This should make the fields of CFactory available to the class C, but the compiler thinks otherwise.

I’m getting the following two errors using gcc on a mac.

error: using template type parameter ‘C’ after ‘class’

error: friend declaration does not name a class or function

Can anyone tell me what I’m doing wrong and how to get et right?

  • 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-23T03:26:22+00:00Added an answer on May 23, 2026 at 3:26 am

    Ise’s response is correct — Comeau’s FAQ contains a question concerning this issue in more detail.

    However, perhaps you can try an extra template indirection that might work? Something like this:

    template <typename T>
    struct FriendMaker
    {
        typedef T Type;
    };
    
    template <typename T>
    class CFactory
    {
    public:
        friend class FriendMaker<T>::Type;
    };
    

    This seems to only work with gcc 4.5.x however so I wouldn’t rely on it.

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

Sidebar

Related Questions

I am writing a small mocking class to do some tests. But this class
I'm writing a small app in qt that is to access some data in
I'm writing a small application in VB.NET and I would like some of the
I'm writing a small agent in java that will play a game against other
I started writing a small wrapper class to take care of my excel operations:
I'm writing a small ajax class for personal use. In the class, I have
I'm currently writing a small script using pygame, but I don't believe this question
I am writing a small class for driving integration testing of a win form
I'm writing a small parser class for a personal project. The class will essentially
For a personal project of mine, I'm writing up a small class to compress

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.