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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:20:58+00:00 2026-06-02T16:20:58+00:00

Suppose I have the following files: main.cpp routine.cpp routine.h Suppose further that main.cpp calls

  • 0

Suppose I have the following files:

  1. main.cpp
  2. routine.cpp
  3. routine.h

Suppose further that main.cpp calls a function routine() that is defined in routine.cpp, but routine.cpp also contains functions that are only used by the routine() function. In other words, routine.cpp contains both functions that are only called from within routine.cpp and functions that are called from other source files.

Obviously main.cpp will contain #include "routine.h". But should routine.h contain prototypes of all functions that are defined in routine.cpp (style A), or should routine.h only contain prototypes of functions that are called from other source files (style B)?

I’ve always written code after style A, but recently I’ve wondered if style B makes more sense stylistically. (If style B is used, then the prototypes of the functions that are used only inside routine.cpp could be at the top of routine.cpp, or the definitions could simply precede their usage.)

  • 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-02T16:20:59+00:00Added an answer on June 2, 2026 at 4:20 pm

    Usually, the header only contains methods of the public interface (if those are free functions). You can declare the auxiliary methods used in routine.cpp in an anonymous namespace.

    //routine.h
    
    void foo();
    void goo();
    
    //routine.cpp
    
    namespace
    {
       void fooHelper() {}
       void gooHelper() {}
    }
    
    void foo()
    {
       fooHelper();
    }
    void goo()
    {
       gooHelper();
    }
    

    Such functions were previously declared static, which gave them internal linkage, but the general style now is to use anonymous namespaces.

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

Sidebar

Related Questions

Suppose i have a php file named main.php It Contains following code include 'config.php';
We suppose that we have the following image (is a single file with 4
Suppose I have the following files: lib/A.h #ifndef A_H #define A_H #include <vector> class
This is a scjp mock exam question. Suppose I have the following two files:
Suppose I have following code: def foo(s): A dummy function foo. For example: >>>
Suppose I have the following directory layout in a Maven project: src/ |-- main
Suppose I have the following program: #include <stdio.h> int main() { printf(This is a
Suppose I have following string: String asd = this is test ass this is
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose you have the following Generic class heirarchy: public abstract class GenericBase<T> { T

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.