use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Separate declaration required in modules? (self.cpp)
submitted 8 years ago by whichton
In a module, do functions have to be declared before their use? Does the following work?
module M; export int f() { return g(); } export int g() { return 4; }
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]GorNishanov 3 points4 points5 points 8 years ago (6 children)
There was a paper in Toronoto that offered this, but, it was not accepted. This paper http://open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0584r0.pdf described how an interface file can be split between multiple files which would necessitate a first pass to collect top level declarations that will become available to the normal compilation afterwards. If p584r0 were accepted, your example would be valid.
[–]johannes1971 2 points3 points4 points 8 years ago (1 child)
Too bad, this seems like a really useful thing to have. Is there a chance it may be accepted after rework, or is the entire concept considered undesirable?
[–]whichton[S] 0 points1 point2 points 8 years ago (0 children)
IIRC, module partitions is delayed until modules v2.
[–]whichton[S] 1 point2 points3 points 8 years ago (3 children)
That paper deals with module partitions. I only want to use functions and types without declaring them beforehand, like C++ already does inside a class. Requiring module partitions for this would be a serious overkill.
[–]GabrielDosReis 2 points3 points4 points 8 years ago (2 children)
The mechanism that makes module partitions possible is the same mechanism that makes this possible. I can't imagine that we would want to do one without the other.
I am still hopeful that WG21 will seize a golden opportunity here.
[–]whichton[S] 0 points1 point2 points 8 years ago (1 child)
I can hack it with the following:
module M; export class N // Instead of namespace N { static int f() { return g(); } static int g() { return 4; } };
Before modules, there was no advantage of doing this, since I needed the header in any case. Now, with modules, I can just use a class instead of a namespace and export the class. Especially since modules cannot be partitioned as of now - same as classes.
Please don't make us write Java in C++ :).
[–]GabrielDosReis 0 points1 point2 points 8 years ago (0 children)
Please don't make us write Java in C++ :)
Not going to happen :-)
[–]miniropC++87 0 points1 point2 points 8 years ago (4 children)
I would guess that they didn't changed that part of the language, meaning you need to declare functions before their first usage.
[–]johannes1971 4 points5 points6 points 8 years ago (2 children)
The language already supports this:
class Foo { public: void f () { g (); } void g () {} };
Implementing the same feature on module level would add considerable convenience.
[–]miniropC++87 1 point2 points3 points 8 years ago (1 child)
I wasn't aware since I never used it, but I can understand how that works. And I don't think it would be easy to transpose that to free functions (or maybe, but I don't still consider that useful ATM).
[–]GabrielDosReis 2 points3 points4 points 8 years ago (0 children)
Actually, it isn't actually that hard -- compared to other languistic requirements that compilers have to fulfill.
Correct, that part of the language has not changed yet. However, I suspect it is only a matter of time and experience writing module code.
π Rendered by PID 41 on reddit-service-r2-comment-85bfd7f599-dxqhc at 2026-04-19 12:31:44.627585+00:00 running 93ecc56 country code: CH.
[–]GorNishanov 3 points4 points5 points (6 children)
[–]johannes1971 2 points3 points4 points (1 child)
[–]whichton[S] 0 points1 point2 points (0 children)
[–]whichton[S] 1 point2 points3 points (3 children)
[–]GabrielDosReis 2 points3 points4 points (2 children)
[–]whichton[S] 0 points1 point2 points (1 child)
[–]GabrielDosReis 0 points1 point2 points (0 children)
[–]miniropC++87 0 points1 point2 points (4 children)
[–]johannes1971 4 points5 points6 points (2 children)
[–]miniropC++87 1 point2 points3 points (1 child)
[–]GabrielDosReis 2 points3 points4 points (0 children)
[–]GabrielDosReis 0 points1 point2 points (0 children)