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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:54:31+00:00 2026-05-11T09:54:31+00:00

In C++, declaration and definition of functions, variables and constants can be separated like

  • 0

In C++, declaration and definition of functions, variables and constants can be separated like so:

function someFunc();  function someFunc() {   //Implementation. } 

In fact, in the definition of classes, this is often the case. A class is usually declared with it’s members in a .h file, and these are then defined in a corresponding .C file.

What are the advantages & disadvantages of this approach?

  • 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. 2026-05-11T09:54:31+00:00Added an answer on May 11, 2026 at 9:54 am

    Historically this was to help the compiler. You had to give it the list of names before it used them – whether this was the actual usage, or a forward declaration (C’s default funcion prototype aside).

    Modern compilers for modern languages show that this is no longer a necessity, so C & C++’s (as well as Objective-C, and probably others) syntax here is histotical baggage. In fact one this is one of the big problems with C++ that even the addition of a proper module system will not solve.

    Disadvantages are: lots of heavily nested include files (I’ve traced include trees before, they are surprisingly huge) and redundancy between declaration and definition – all leading to longer coding times and longer compile times (ever compared the compile times between comparable C++ and C# projects? This is one of the reasons for the difference). Header files must be provided for users of any components you provide. Chances of ODR violations. Reliance on the pre-processor (many modern languages do not need a pre-processor step), which makes your code more fragile and harder for tools to parse.

    Advantages: no much. You could argue that you get a list of function names grouped together in one place for documentation purposes – but most IDEs have some sort of code folding ability these days, and projects of any size should be using doc generators (such as doxygen) anyway. With a cleaner, pre-processor-less, module based syntax it is easier for tools to follow your code and provide this and more, so I think this ‘advantage’ is just about moot.

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

Sidebar

Related Questions

Can someone explain to me a variable declaration inside a definition of a function,
Given a declaration like this: class A { public: void Foo() const; }; What
Is this function declaration in C#: void foo(string mystring) the same as this one
This is for C++. Usually we have our function declaration in header file and
Declaration;) MKMapView mapView; I can't found the difference between mapView.userLocation.location.coordinate and mapView.userLocation.coordinate. Is there
This declaration causes an overflow in VBA: Const OVERFLOWS As Long = 10 *
Given this C API declaration how would it be imported to C#? int _stdcall
Possible Duplicate: What is the difference between a definition and a declaration? I am
I'm trying to redefine two member functions from their parent's definition. I don't know
I am having a problem with friend functions. I figure this is the only

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.