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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:36:22+00:00 2026-06-08T11:36:22+00:00

I have 3 files Test.h , Test.cpp and main.cpp Test.h #ifndef Test_H #define Test_H

  • 0

I have 3 files Test.h , Test.cpp and main.cpp

Test.h

#ifndef Test_H
#define Test_H
 namespace v
{
    int g = 9;;
    }
class namespce
{
public:
    namespce(void);
public:
    ~namespce(void);
};
#endif

Test.cpp

   #include "Test.h"


namespce::namespce(void)
{
}

namespce::~namespce(void)
{
}

Main.cpp

#include <iostream>
using namespace std;
#include "Test.h"
//#include "namespce.h"


int main ()
{

    return 0;

}

during building it gives the following error ..

1>namespce.obj : error LNK2005: "int v::g" (?g@v@@3HA) already defined in main.obj
1>C:\Users\E543925\Documents\Visual Studio 2005\Projects\viku\Debug\viku.exe : fatal error LNK1169: one or more multiply defined symbols found

kindly help as soon as possible ..

  • 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-08T11:36:24+00:00Added an answer on June 8, 2026 at 11:36 am

    You have two options:

    static:

    namespace v
    {
        static int g = 9; //different copy of g per translation unit
    }
    

    extern:

    namespace v
    {
        extern int g; //share g between units
    }
    
    // add initialization to .cpp:
    namespace v { int g = 9; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three files: 1. Joy.h class Joy { public: void test(); }; 2.
I have two files: // event_test_delete.cpp #include <event.h> int main() { event_base* ev; ev
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
I have two precompiled library: X.a and Y.a and a test.cpp (without main function)
I have this abstract base class ODESolver: //ODESolver.h #ifndef ODESolver_H #define ODESolver_H #include doublependulum.h
I have two files once is named as test.cpp and another as ani.cpp. test.cpp
I have a main.cpp test.h and test.cpp> I am trying to pass my vector
I have the following 3 files (1 *.cpp and 2 *.hpp) : the main
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
If, for example, I have a directory which contains the following files: Test-20120626-1023.txt Test-20120626-0710.txt

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.