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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:33:47+00:00 2026-05-26T20:33:47+00:00

I have two header files A.h(include a pure virtual function) and B.h. A.h :

  • 0

I have two header files A.h(include a pure virtual function) and B.h.

A.h :

#ifndef __A_H__
#define __A_H__

#include "B.h"
template <class T>
class A
{
   virtual B<T> f()=0;
};

#endif

B.h :

#ifndef __B_H__
#define __B_H__

#include "A.h"
template <class T>
class B : public A <T> 
{
  B<T> f(){}
};

#endif

but when I compile it gives me error like that
In file included from B.h:4,
from Test.cpp:1:
A.h:10: error: ISO C++ forbids declaration of ‘B’ with no type
A.h:10: error: ‘B’ declared as a ‘virtual’ field
A.h:10: error: expected ‘;’ before ‘<’ token

#include "B.h"

int main() {
 return 0;
}

how can I solve this ?
thanks

  • 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-26T20:33:47+00:00Added an answer on May 26, 2026 at 8:33 pm

    The only way is with forward declare :

    #ifndef __A_H__
    #define __A_H__
    
    template< typename > class B;
    
    template <class T>
    class A
    {
       virtual B<T>* f()=0;
    };
    
    #endif
    

    You have a problem with circular dependency which can be solved only using forward declare.

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

Sidebar

Related Questions

Hello ever one I have made a main function and two files one header
I have a class. I have made two seperate files, the header, and the
I have this situation (two classes with two different header files): b.h #include a.h
I have two classes, and want to include a static instance of one class
I have two header files named string.h in different libraries, they are conflicted with
What I'm trying to do: I have two files: One is the header.php which
I have a template matrix class class defined in a header called Matrix.h. Certain
I will have two files. One header.h file and second one is main.c file.
I have these two header files and one produces an error if I don't
Can i add two header text in Datagrid? My Requirement is to have two

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.