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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:12:07+00:00 2026-05-27T01:12:07+00:00

Let’s assume there are four files: foo.h, foo.cpp, bar.h, bar.cpp. foo.h: #pragma once class

  • 0

Let’s assume there are four files: foo.h, foo.cpp, bar.h, bar.cpp.

foo.h:

#pragma once

class foo
{
    // Whatever
};

foo.cpp

#include "foo.h"

// Foo's definitions

bar.h

#pragma once

class bar
{
    bar(const foo & f); // < C4430 'missing type specifier' (not always)
    // Other declarations
};

bar.cpp

#include "foo.h"
#include "bar.h"

// Bar's definitions

The compiler says there is C4430 in bar.h. But the strange thing is that I’m able to build the code by commenting and then uncommenting back that line. Of course, build fails with the line being commented as well, but when I uncomment it I get successful build. So the same code may or may not produce errors.

My VS is 10.0.40219.1 SP1Rel and the project type is Win32 DLL.

  • 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-27T01:12:08+00:00Added an answer on May 27, 2026 at 1:12 am

    You need to include foo.h in bar.h:

    #pragma once
    
    #include "foo.h"
    class bar
    {
        bar(const foo & f);
    };
    

    If you need a full class definition, which you do unless you’re using a pointer (in which case a forward declaration would suffice), you need to include the file where the class is declared.

    Why does it compile sometimes and sometimes it fails?

    Depends on the compiler. My guess is foo.h is included in a file that gets compiled before bar.h is reached. So bar.h already knows about foo‘s definition. If the build fails, the files that were succesfully compiled are skipped, and possibly foo.h no longer included. Or if you make a change only in x.cpp, the compiler will only build that file and possibly skip the inclusion of foo.h, which was included in a file that is already compiled.

    I hope I was clear.

    Why what you already have isn’t enough?

    You might say that

    //Bar.cpp
    #include "foo.h"
    #include "bar.h"
    
    // Bar's definitions
    

    includes foo.h before bar.h. Indeed, but what if bar.h is included before foo.h in a different place? That’s why it is a good idea to include foo.h in bar.h. Any file including bar.h will no longer need to include foo.h (which it must in order to compile), and it makes more sense to include everything you need in the file. This isn’t the case with forward declarations, but, again, you’re using a complete type, not a pointer.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's aggregate a list of free quality web site design templates. There are a
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's assume that we are building a high traffic site that will be used
Let's say there is a graph and some set of functions like: create-node ::
Let's say I have the string: hello world; some random text; foo; How could
Let's imagine I have a Java class of the type: public class MyClass {
Let's assume I want to deserialize this (I've removed the namespaces to make things
Let's suppose I've got a 2D vector template class: template<typename T> class Vec2 {

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.