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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:29:41+00:00 2026-05-29T15:29:41+00:00

I’m working on a C++ project. I had a class with its function, then

  • 0

I’m working on a C++ project.

I had a class with its function, then I realized some of those functions weren’t related to that class but were just math functions so I decided to move them on to a namespace.

My first question is, what is the appropriate file extension for a c++ namespace?

I have a constants.h file where I plan on saving global constants, for example PI.

Right now:

#include <math.h>
const double PI = M_PI;

I have the namespace I talked about before, right now is called: specificMath.h

#include <stdlib.h>
#include "constants.h"
... more code

I have a gaussian.cpp:

#include "gaussian.h"
#include "specificMath.h"
#include <iostream>
... more code

This file includes a main function that right now does nothing, I just can’t get the whole project to compile without a main…

I have a gaussian.h where I’m not including anything, is that wrong?

A third class, which has no attributes, just methods (again, is this wrong? or not pretty?). truncatedFunctions.cpp

#include "specificMath.h"
#include <stdlib.h>
#include "truncatedFunctions.h"
#include "gaussian.h"

using namespace specificMath;

And its truncatedFunctions.h where, again, I’m not including anything.

And a fourth class where I include

#include "margin.h" //Its header, where I'm not including anything
#include "gaussian.h"
#include "specificMath.h"

using namespace specificMath;

When I “make” it, it seems to compile fine, but when it gets to the linking part I get A LOT of errors saying that things on my margin.cpp class were first defined in truncatedFunctions.cpp

I am going crazy. I have no idea why this is happening, or how to solve it. I would really appreciate if somebody could help me out, and please, any extra piece of advice would be great since I am really trying to learn as much as I can with this project. 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-29T15:29:44+00:00Added an answer on May 29, 2026 at 3:29 pm

    When I “make” it, it seems to compile fine, but when it gets to the linking part I get A LOT of errors saying that things on my margin.cpp class were first defined in truncatedFunctions.cpp

    Did you define your functions in your specificMath.h? You should only declare those functions.

    For example, if your specificMath.h contains function definitions like

    #ifndef COOL_STUFF_NSPC
    #define COOL_STUFF_NSPC
    #include <iostream>
    namespace coolstuff{
        void print(void){std::cout << "I'm declared in a header file." << std::endl;
    }
    #endif
    

    and you are using including this file in several others, the linker is going crazy. Including means copying. And so you’ve got yourself coolstuff::print defined several times. The better way (and the only possible way when using self-written functions in many files) is splitting your code into a header and implementation as you did in gaussian.

    // coolstuff.namepace.h
    #ifndef COOL_STUFF_NSPC
    #define COOL_STUFF_NSPC
    namespace coolstuff{
        void print(void);
    }
    #endif
    

    When you include coolstuff.namespace.h it will only declare functions. And you can declare the same function several times.

    // coolstuff.namespace.cpp
    #include <iostream>
    #include "cs.h"
    
    void coolstuff::print(void){
        std::cout << "Hello world!" << std::endl;
    }
    

    The .cpp file contains the implementation of your functions. Now your linker won’t get irritated because there is only one implementation of coolstuff::print and not n (where n is the number of #include "cs.namespace.h" you used) ones.

    My first question is, what is the appropriate file extension for a c++ namespace?

    There is no standard namespace extension. Use .h/.cpp for header/implementation and a self-defined prefix, something like ‘nmspc’ or ‘nsc’. It’s up to you.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.