Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


namespace float redefinition


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 31 March 2013 - 12:59 PM

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

 

1.h

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?!



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5413

Like
2Likes
Like

Posted 31 March 2013 - 01:02 PM

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

 

#endif

 

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


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 31 March 2013 - 01:04 PM

damn! you are right ...can't believe i didn't notice this.Thanks a lot!



#4 Paradigm Shifter   Crossbones+   -  Reputation: 5413

Like
4Likes
Like

Posted 31 March 2013 - 01:09 PM

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 ;)


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS