Jump to content
  • Advertisement
Sign in to follow this  

namespace float redefinition

This topic is 2030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I've been messing around with namespaces,here's what I have:



namespace x{
void d();

float j;
int m();




When i compile that I get this:

'float x::j' : redefinition


I don't understand,what am I doing wrong?!

Share this post

Link to post
Share on other sites

Looks like the header is getting included more than once in a file. You need include guards or #pragma once


Include guards look like this:


#ifndef INCLUDED_1_H

#define INCLUDED_1_H


// contents of header file




Each header file needs a uniquely named #define when doing it the include guards way.

Share this post

Link to post
Share on other sites

Also, the reason it didn't moan about d() or m() being redefined is because function declarations are implicitly extern (unless static). You could get away with no include guard (not recommended though) if you had


extern float j;


in the header and defined it as


float x::j;


in one and only one cpp file (presumably, 1.cpp).


And I hope the file name and variable names are just for illustration, otherwise, you're fired ;)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!