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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:08:58+00:00 2026-06-17T13:08:58+00:00

This one is making me scratch my head too long. I have the following

  • 0

This one is making me scratch my head too long.

I have the following in a header test.h:

inline void anything(){
std::cout<<" anything "<<ii;
}

Then I have a.h, which includes test.h:

class Fooness{
public: 
Fooness(){
    anything(); //compiler reports "use of undeclared identifier"
    };
};

HOWEVER, if I simply move the function definition to a.cpp:

Fooness::Fooness(){
anything();
}

It works. a.cpp includes test.h which includes a.h. Why is anything() only visible in a.cpp not a.h?

  • 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-06-17T13:08:59+00:00Added an answer on June 17, 2026 at 1:08 pm

    As you pointed out in the comments, you included a.h in test.h and vice versa. This introduces errors as functions and classes being “undefined” because of a cyclic dependency, also known as cross-include.

    In your case, when a .cpp file includes test.h, it first includes a.h and then defines the function anything();, which is obviously not what you want, since when processing a.h, anything() is undefined.

    Your code expands to something similar to this, when compiling a unit which includes test.h (before a.h), which by itself includes a.h before anything else:

    /* INCLUDED FROM a.h */
    class Fooness{
    public: 
    Fooness(){
        anything();
        };
    };
    
    inline void anything() {
        ....
    }
    

    As you see, there is no anything() defined when you use it. However, if a compilation unit includes a.h (before test.h), which itself includes test.h, it expands to something like this:

    /* INCLUDED FROM test.h */
    inline void anything() {
        ....
    }
    
    class Fooness{
    public: 
    Fooness(){
        anything();
        };
    };
    

    So the order is correct.

    To make it work in both situations, you can forward-declare anything() in test.h before you include a.h:

    Corrected version of test.h:

    #ifndef TEST_H
    #define TEST_H
    
    void anything(); // forward-declaration
    
    #include "a.h"   // <-- this is important to be *below* the forward-declaration
    
    inline void anything() {
        ....
    }
    
    // more stuff
    
    #endif
    

    Then, when including test.h (before a.h), it expands to the following:

    void anything();
    
    /* INCLUDED FROM a.h */
    class Fooness{
    public: 
    Fooness(){
        anything();
        };
    };
    
    inline void anything() {
        ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one is a real head scratcher for me... var matches = Regex.Matches(<p>test something<script
This one is making my head spin. Just when I think I got it,
This one is really making me pull my hair out. I have written a
Once again, I'm at a loss with IE7 on this one. I'm making a
I'm making a piano application in Java. This is one of the functions, public
This one's a head scratcher. I've created a commented jsFiddle to demonstrate the phenomenon
This one's got me stumped and it's driving me nuts. I have a SiteFinity
This one is a little tricky. Say I have this XmlDocument <Object> <Property1>1</Property1> <Property2>2</Property2>
Followup question from this one: Swing font names do not match? (Making a font
First time making a Javascript script from scratch. This works perfectly in Firefox, but

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.