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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:52:25+00:00 2026-06-09T21:52:25+00:00

I have Hello World code that uses function fhi from another hi.cpp file that

  • 0

I have “Hello World” code that uses function fhi from another hi.cpp file that has it’s header.

Correct my if my understanding is wrong according following:

I can do include cpp file like #include "c:\c\hi.cpp" instead of using header without any problems except that fact that it looks more readable in header file.

If I include header like sample in my main program hi.h, must hi.h include hi.cpp, or it is done automatically according the same file name hi. I’m wondering how compiler knows where is function fhi body.

Is it possible to have different names for header and cpp files?

Programm:

#include "stdafx.h"
#include "c:\c\hi.h"


int _tmain(int argc, _TCHAR* argv[])
{
fhi(1);
return 0;
}

hi.h

 #include <cstdlib>
 #include <iostream>

 int var;
 int  fhi(int f);

hi.cpp

 #include <cstdlib>
 #include <iostream>

 int  fhi(int f)
 {
 return 0;
 }
  • 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-09T21:52:26+00:00Added an answer on June 9, 2026 at 9:52 pm

    must hi.h include hi.cpp

    No. hi.h contains only declarations, that can be other by other .cpp files.

    I’m wondering how compiler knows where is function fhi body.

    It doesn’t. You need to compile all *.cpp files into the object files. In your case, you will have two object files: program.o and hi.o. The linker can now take these two object files, and spit out the executable. References to other functions(in this case the actual definition of fhi(..)) is resolved in this stage.

    Also why are you using absolute paths in #includes? It will break when you move the “c” directory around.

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

Sidebar

Related Questions

I have C code that uses prints with something clever like printf("hello "); //
I have code as below: var s : String = hello world var xml
I have a C++ DLL with code like this: LogMessage( Hello world ); try
I have next code require 'rack/rpc' class Server < Rack::RPC::Server def hello_world Hello, world!
Say I have the following code: <span>Hello world!</span> And the following CSS: span{ color:red;
I have run this Perl code: #!/usr/bin/perl print content-type: text/html \n\n; print Hello World.\n;
I have the following form code: # forms.py class SomeForm(forms.Form): hello = forms.CharField(max_length=40) world
suppose I have simple C# code to print HELLO WORLD as shown in here
I have some code that has a dynamic-class system in C++ that has a
I have the following Hello World code to try out TeX rendering with matplotlib

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.