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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:07:02+00:00 2026-06-08T05:07:02+00:00

I have the following 3 files (1 *.cpp and 2 *.hpp) : the main

  • 0

I have the following 3 files (1 *.cpp and 2 *.hpp) :

the main program file:

// test.cpp

#include<iostream>
#include"first_func.hpp"
#include"sec_func.hpp"

int main()
{
    double x;
    x = 2.3;
    std::cout << sec_func(x) << std::endl;
}

–
the first_func.hpp header:

// first_func.hpp

...

double  first_func(double x, y, x)
{

    return x + y + x;
}

–
the sec_func.hpp header:

// sec_func.hpp

...

double sec_func(double x)
{
        double a, b, c;
        a = 3.4;
        b = 3.3;
        c = 2.5;

        return first_func(a,b,c) + x;
}

How do I properly call first_func from within the sec_func.hpp file?

  • 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-08T05:07:03+00:00Added an answer on June 8, 2026 at 5:07 am

    It’s a bad practice to place function definition to .hpp files. You should place only function prototypes there. Like this:

    first_func.hpp:

    double  first_func(double x, double y, double x);
    

    first_func.cpp:

    double  first_func(double x, double y, double x)
    {
        return x + y + x;
    }
    

    The same for second func.

    And then, wherever you want to call your first_func, you just include corresponding first_func.hpp in that cpp module, and write the call.

    Thus, every your module consists of hpp with all declarations, and cpp with definitions (that is, the bodies). When you need to reference something from this module, you include its hpp and use the name (of constant, variable, function, whatever).

    And then you must link everything together:

    gcc main.cpp first_func.cpp second_func.cpp -o program
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following three files in the same directory: citysim.cpp #include utils.h using
I have created a file called untitled1.cpp in dev-cpp with the following script: #include
i have following code in c++ #include <iostream> using namespace std; void qsort5(int a[],int
Static variable has file scope. Say I have two following files: file1.h file1.cpp file2.h
I have a main.cpp like so: #include <boost/python.hpp> const char* greeting() { return Hello
I have a header file... #include <SFML\Graphics.hpp> #include <SFML\Graphics\Drawable.hpp> #include <SFML\System.hpp> #include <iostream> #ifndef
I have the following files: listDriverTest.cpp src/List.cpp headers/List.h The include in List.cpp is #include
Suppose I have the following files: main.cpp routine.cpp routine.h Suppose further that main.cpp calls
Assume the following scenario. I have two files A.cpp and B.cpp in trunk. At
I have 5 files: ExecutionStrategyInterface.h ExecutorInterface.h TaskCollectionInterface.h TaskExecutor.h TaskExecutor.cpp . TaskExecutor implements the following

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.