-1

I currently have a namespace set up like this:

SomeClass.h

namespace somenamespace {
    class SomeClass {
        public: 
            foo();
    }
}

SomeClass.cpp

namespace somenamespace {
    SomeClass::foo() {
        somehelperfunction();
    }
}

void somehelperfunction() {
    std::cout << "hejflsdjf\n";
}

Without changing my header file, I cannot find a way to implement this helper function in a way which allows my class implementation to access the helper function. I was under the impression that as long as the helper function was in the same file I would be able to access it within the class implementation. But I get a "undeclared identifier" error when trying to build.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
DucksEatTurtles
  • 194
  • 1
  • 2
  • 10
  • You have to declare `somehelperfunction()` before calling it. – The Coding Fox Mar 12 '22 at 06:16
  • @SolvedGames I hate c++ – DucksEatTurtles Mar 12 '22 at 06:17
  • I also hate stackoverflow. Debugging issue? I didn't even know I had to put the declaration before calling it. How can I bebug something I didn't know had to happen? I thought my "declare before using" was over after I left C – DucksEatTurtles Mar 12 '22 at 06:18
  • Relax man. That's just how C++ works. C++ is basically an extension of C. – The Coding Fox Mar 12 '22 at 06:20
  • 1
    @SolvedGames "*C++ is basically an extension of C*" - that may have been true in the early days, but that hasn't been true for a very long time. They have both evolved into very different languages. – Remy Lebeau Mar 12 '22 at 06:22
  • @RemyLebeau I mean yes that's true with the newer things like `ranges` but I was just saying it averagely. – The Coding Fox Mar 12 '22 at 06:24
  • @Ducks *"How can I bebug something I didn't know had to happen?"* -- that is not what the close reason requests. You are not asked to successfully debug the issue, only to provide debugging details. Personally, I disagree with closing for that reason, but I can see a point in that you are missing one key detail: the exact error message, pasted (as text) into your question. Simplifying to just the kind of error ("undeclared identifier") tends to be over-simplification; the full error message would include lots of potentially useful *debugging details*, such as which identifier and where. – JaMiT Mar 12 '22 at 06:44
  • I might vote to re-open, but I then I would vote to close as a duplicate. ['get_call' was not declared in this scope](https://stackoverflow.com/questions/19341405/) - [Calling a free floating function within a class](https://stackoverflow.com/questions/22059261/) - [Identifier not found when calling a function under a function](https://stackoverflow.com/questions/70818107/) - [Why can my merge function for mergeSort not be found?](https://stackoverflow.com/questions/71107563/) - [How can I define the function used in a function template?](https://stackoverflow.com/questions/57875004/) – JaMiT Mar 12 '22 at 06:50
  • @JaMiT it is not what we don't know but what we don't know we don't know which poses the greatest threat - sun tzu probably – DucksEatTurtles Mar 21 '22 at 03:53
  • As for the debugging issue, I'm new to cpp development and that was all my IDE gave me for an error. I'll try and see if I can get errors from my compiler next time. – DucksEatTurtles Mar 21 '22 at 03:54

1 Answers1

0

Functions must be declared before called.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
DucksEatTurtles
  • 194
  • 1
  • 2
  • 10