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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:36:25+00:00 2026-06-07T09:36:25+00:00

First, a more abstract question. Is it good practice to use a namespace instead

  • 0

First, a more abstract question. Is it good practice to use a namespace instead of a class, in terms of speed, when you don’t need a constructor/destructor or multiple copies of said object?

Second, I get ” ccEaV3B0.o:main.cc:(.text+0x10): undefined reference to `board::arbi’ ” when trying to include and use a namespace. I’m using Mingw32 on Windows 7, with the make command: g++ -Wall main.cc board.cc

This also happens when I compile seperately, using:
g++ -c board.cc
g++ -Wall main.cc board.o

Here are the (minimal) files:

main.cc:

#include <iostream>
using namespace std;

#include "board.h"

int main(){
    cout << board::give() << endl;
    return 0;
}

board.h:

#ifndef BOARD_H
#define BOARD_H

namespace board {
    extern int arbi;
    extern int give();
}

#endif

board.cc:

#include "board.h"

int board::give(){
    return arbi;
}

Solved by giving an initialisation “int board::arbi = 5;” in board.cc

The question remains why you should use a class when something is clearly an object, even if you know there will always be exactly one instance of said object. It seems to me you would want globals, but to avoid name-clashing, you would put them in a namespace.

  • 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-07T09:36:27+00:00Added an answer on June 7, 2026 at 9:36 am

    You need to define board::arbi in the board.cc file.

     int board::arbi = <whatever initial value>;
    

    With the extern declaration you only comforted the compiler that you will provide the definition later, but you didn’t provide one.

    Regarding the abstract question, the concept of class and namespace is very different. Class defines structure for objects which are ‘real’. i,e,they occupy memory. Namespace is just like a fence restricting the scope of global variables. They don’t occupy memory…. So, if you see logical objects in your program define them as classes. But, if you see only a set of global functions which are somehow related, but you can’t imagine them as a coherent object, use namespace.

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

Sidebar

Related Questions

first time use JTree. Just wondering is it possible to have more than one
This is kinda....a two part question. The first one is much more important than
When people discuss about internationalization, they use the word i18n more often. For first
Which static class initializes first if we have one more static classes in our
Original Question Consider the following scenario: public abstract class Foo { public string Name
(edit) more info. First notice new virtual. This class inherits a base class which
It's the first time I use java Rmi*. I have a custom class which
First off, I understand the reasons why an interface or abstract class (in the
This is a bit of an abstract question, so I'll provide the necessary use
In the following examples: the first seems more verbose but less wasteful of resources

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.