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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:15:21+00:00 2026-05-29T19:15:21+00:00

File ex1.hpp (definition of template class): #ifndef EX1_HPP #define EX1_HPP #include ex2.hpp template <class

  • 0

File ex1.hpp (definition of template class):

#ifndef EX1_HPP
#define EX1_HPP

#include "ex2.hpp"

template <class T>
class Ex1{
public:
    void Ex1method(){
        Ex2 a; // using nontemplate class object
        a.Ex2method();
    }
};

#endif

File ex2.hpp (definition of nontemplate class):

#ifndef EX2_HPP
#define EX2_HPP

#include "ex1.hpp"

class Ex2{
public:
    void Ex2method();
};

#endif

File ex2.cpp (definition of nontemplate class method):

#include "ex2.hpp"

void Ex2::Ex2method()
{
    Ex1<int> e; // using template class object
    e.Ex1method();
}

Compilation error:

ex1.hpp:10:9: error: ‘Ex2’ was not declared in this scope
ex1.hpp:10:13: error: expected ‘;’ before ‘a’
ex1.hpp:11:9: error: ‘a’ was not declared in this scope

How can be such circular dependency between nontemplate class and template class resolved? I cannot be definition of nontemplate class methods to implementation file, because it will cause linker error. If I place forward declaration of Ex2 class in file ex1.hpp, then error is:

error: invalid use of incomplete type ‘struct Ex2’
error: forward declaration of ‘struct Ex2’
  • 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-29T19:15:22+00:00Added an answer on May 29, 2026 at 7:15 pm

    Don’t include ex1.hpp in ex2.hpp, it is not necessary there. You don’t have a circular dependency with your headers.

    Include both headers (or just ex1.hpp) in your .cpp file and all should be good.

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

Sidebar

Related Questions

File A.h #ifndef A_H_ #define A_H_ class A { public: virtual ~A(); virtual void
FILE #1 (foo.h): #ifndef FOO_H_ #define FOO_H_ #include baseclass.h #include bar.h class Bar; class
File structure customerService.PHP include 'vo/VOCustomer.php'; include 'mydb.php'; class customerService { public function createCustomer(VOCustomer $cus)
// File foo1.c : #include <stdio.h> // once void foo1(void); void foo1(void){ puts(foo1); }
File formats I would like to play include .wav, .mp3, .midi. I have tried
File is sent to the client using Response.writefile and content diposition as inline. When
file.txt contains: ##w## ##wew## using mac 10.6, bash shell, the command: cat file.txt |
// File: foo.c static int var; void foo() { var++; } // end of
I am developing an app with three activities called Activity Ex1, Ex2 and Ex3.
I want to define an XSD to an XML file, but I don't know

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.