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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:30:00+00:00 2026-05-25T22:30:00+00:00

My code has the same structure as the shown below. I have two container

  • 0

My code has the same structure as the shown below. I have two container classes defined in a single header file and each one of them has a friend function with parameters of type the other class so I get a compiling error which is something like ‘Class2’ – undeclared identifier.

Tried a few things but didn’t work it out. I think that if add one more template parameter V to both of the templates and replace Class2<T> with it could be a solution but thing get much complicated if I use these containers in my program.I also thought to separate Class1 and Class2 into different headers and then include in Class1 Class2 and vice versa but I actually I doubt that this could work at all.

I really can’t figure out how to solve this problem so please your help is much appreciated!

template<class T>
class Class1
{
  ...
  friend void function1(Class1<Class2<T>>&, const Class2<T>&);
  ...
};

template<class V>
class Class2
{
   ...
   friend void function2(Class1<V>);
   ...
};
  • 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-25T22:30:00+00:00Added an answer on May 25, 2026 at 10:30 pm

    Add a forward declaration for Class2 at the beginning of the file:

    template<class V> class Class2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have WPF Form which has many buttons with the same code. Appearance of
My code has something like this: HttpFileCollection files Instead of looping through each file
In my WPF4 desktop application all windows have the same structure — header &
Can you have a structure in C that has elements of that same structure?
I have heard of desktop applications whose code has been open-sourced, but are there
I have a data structure object which is loaded from an XML file inside
This code has an interesting bug: some_struct struct_array1[10] = {0}; some_struct struct_array2[10] = {0}
The code has a runtime dependency which is not available in our development environment
The following code has a simple binding which binds the Text of the TextBlock
So this code has the off-by-one error: void foo (const char * str) {

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.