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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:00:56+00:00 2026-05-19T11:00:56+00:00

http://www.learncpp.com/cpp-tutorial/19-header-files/ It mentions the following as another solution to forward declaration: A header file

  • 0

http://www.learncpp.com/cpp-tutorial/19-header-files/

It mentions the following as another solution to “forward declaration”:

A header file only has to be written once, and it can be included in as many files as needed. This also helps with maintenance by minimizing the number of changes that need to be made if a function prototype ever changes (eg. by adding a new parameter).

But, cannot this also be made with “forward declaration”? Since we are defining the function int add(int x, int y) for example in “add.cpp”, and using this function in “main.cpp” by typing:

int add(int x, int y);

?
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-19T11:00:56+00:00Added an answer on May 19, 2026 at 11:00 am

    That is certainly possible. But for a realistically-sized program, there will be a large number of functions that a large number of other files will need to declare. If you put a forward declaration in every file that needs to access another function, you have a multitude of problems:

    1. You’ve just copy-pasted the same declaration into many different files. If you ever change the function signature, you have to change every place you’ve pasted its forward declaration.
    2. The forward declaration itself does not naturally tell you what file the actual function is defined in. If you use a sane method of organizing your header files and your source files (for instance, every function defined in a .cpp file is declared in a .h file with the same name), then the place that the function is defined is implied by the place that it is declared.
    3. Your code will be less readable to other programmers, who are very used to using header files for everything (for good reason), even if all you need from a header is one specific function and you could easily forward-declare it yourself.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the end of the artile here: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/ It mentions the following sentence: Finally,
At the end of the article here: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/ , it mentions the following: Finally,
At: http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/ It has the following code: // Declare a DateStruct variable DateStruct sToday;
http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/ I have been about this lately to review C++. In general computing class
http://www.ioplex.com/jespa.html I am following the example as described in Providing NTLM Services without Active
EX : http://www.facebook.com/plugins/likebox.php?id=144375998956146&width=250&connections=8&stream=true&header=true&height=700 I need to steam normal user posts too... but this demo
How to do that: http://download.oracle.com/javase/tutorial/uiswing/components/spinner.html using that: http://www.scala-lang.org/api/current/index.html#package ?
http://www.codeplex.com/IIRF/Thread/List.aspx My webhost installed IIRF for me and I am convinced that they did
From http://www.jibbering.com/faq/faq_notes/closures.html : Note: ECMAScript defines an internal [[prototype]] property of the internal Object
This web page http://www.w3schools.com/ASP/prop_sessionid.asp states that a session ID is generated on the ServerSide.

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.