Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Trying to makes sense of unnamed namespace and extern use


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 sonar87


    CC Newcomer

  • Member
  • PipPip
  • 21 posts

Posted 25 January 2017 - 01:17 PM

I have a program with with two .cpp files (one being main, the other with a couple functions) and two .hpp files so far (one with function definitions for the one .cpp file, the other with some includes like iostream that all the .cpp files use).


The following is at the start of my main file

  extern const int max = 10;

And then I have the same but not assigning it a value, just ; after the word max, in the .hpp file with the includes. This is included in main and in the .cpp file for the function definitions. But I'm getting an "undefined reference to `(anonymous namespace)::max' error when one of my functions tries to use it. Is this the wrong way to use the extern thing?


#2 AceInfinity


    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts

Posted 29 January 2017 - 12:52 PM

extern is for the declaration only, not the assignment. Why do you have an unnamed namespace?

Edited by AceInfinity, 29 January 2017 - 12:53 PM.

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download