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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:13:39+00:00 2026-06-09T15:13:39+00:00

If I have a project with main .cpp Knife .h and .cpp Cucumber .h

  • 0

If I have a project with

main .cpp 
Knife .h and .cpp
Cucumber .h and .cpp 

and I want to use Knife’s members in Cucumber, does it matter whether I use the following:

#include "Knife.h"
#include <iostream>
using namespace std;

in Cucumber.h or Cucumber.cpp (assume that Cucumber.cpp already has an include for Cucumber.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-09T15:13:40+00:00Added an answer on June 9, 2026 at 3:13 pm

    My recommendation is to minimize the number of files included in the header files.
    So, if I have the choice, I prefer to include in the source file.

    When you modify a header file, all the files that include this header file must be recompiled.

    So, if cucumber.h includes knife.h, and main.cpp includes cucumber.h, and you modify knife.h, all the files will be recompiled (cucumber.cpp, knife.cpp and main.cpp).

    If cucumber.cpp includes knife.h and main.cpp includes cucumber.h, and you modify knife.h, only cucumber.cpp and knife.cppwill be recompiled, so your compilation time is reduced.

    If you need to use knife in cucumber you can proceed like this:

    // Cucumber.hpp
    #ifndef CUCUMBER_HPP
    #define CUCUMBER_HPP
    
    class Knife;
    
    class Cucumber
    {
    public :
    ///...
        private :
        Knife* myKnife
    }
    #endif
    
    //Cucumber.cpp
    #include "Cucumber.hpp"
    #include "Knife.hpp
    
    // .. your code here
    

    This “trick” is called “forward declaration”. That is a well-known trick of C++ developers, who want to minimize compilation time.

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

Sidebar

Related Questions

// diskbin.cpp : main project file. #include stdafx.h #include <windows.h> #include <iostream> #include <fstream>
I have a project that has some main.cpp and the following precompile header: <!--
I have a code like this below in /root_project/main.cpp : #include theoraplayer/TheoraVideoClip.h unsigned int
I have a project in which i have the following files main.wxs - directory
I have the following project. The main form has control in it. This control
I have the file main.cpp open in my editor. I want to see the
I have started a new project consisting of one main.cpp file and an additional
I have a main.cpp like so: #include <boost/python.hpp> const char* greeting() { return Hello
In my project i have 2 ui files (mainwindow.ui,myform.ui),2 source files(main.cpp,mainwindow.cpp) and 1 header
I have one main project and another project which is added as a subprojects.

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.