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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:40:38+00:00 2026-05-24T01:40:38+00:00

Lets say I have 3 files: add.h, add.cpp and main.cpp. This is a common

  • 0

Lets say I have 3 files: add.h, add.cpp and main.cpp. This is a common example on C++ training sites where add.h contains the prototype of a function called “add”. Add.cpp contains the declaration of the prototype and main.cpp includes add.h and then calls the add() function to add two numbers (x and y) together.

My question is this: No matter what I name add.cpp, my program works just fine. Elephant.cpp works just as well as doctorWhoRules.cpp. Does the compiler search through all the local .cpp files to find the given prototype in add.h? I don’t declare the name of the .cpp file that contains it anywhere. I’m just confused as to how this works.

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-24T01:40:39+00:00Added an answer on May 24, 2026 at 1:40 am

    I think you are mixing Java with C++. In Java (editors like Eclipse) there is a general restriction that, your class name should same as the file name. i.e.

    // Add.java
    class Add
    {
    }
    

    In C++ there are no such restrictions. Your file name can be any meaningful name. The only thing you have to take care is that your implementation files are with .cpp/.cxx/.C etc. extensions (I don’t know if modern compilers support other than this also).

    Even your header file can be any arbitrary extension of course other than .cpp and all; the more conventional extensions for header files are .h, .hpp etc.

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

Sidebar

Related Questions

I have 2 mxml files, lets say main.mxml and child.mxml. Now lets say I
Lets say I add this to my module: function example_preprocess(&$vars,$node) { $vars['theme_hook_suggestions'][] = 'example__page_'.$node;
Let's say you have a text file like this one: http://www.gutenberg.org/files/17921/17921-8.txt Does anyone has
I have a header file, lets say Common.h, that is included in all of
Hoping someone can help me out with this. Lets say I have a table
Ok lets say I have a File called File.txt and it contains Hello World
Let's say I have two files default.aspx and the associated default.aspx.cs . default.aspx.cs: protected
Lets say I have 10 lines in a file. I have 2 parameters that
Lets say I have a few utility functions in file tests/utils/functions.js. I would like
Let's say I have css1.css and css2.css. Just for the sake of keeping files

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.