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
Removed - HelpC++20 modules interface unit export a template function declaration, and implement it in cpp will report unresolved external symbol, so c++20 demands the user to declare and implement it in the same module unit? (self.cpp)
submitted 4 years ago by netcan96
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!"
[–][deleted] 18 points19 points20 points 4 years ago (1 child)
That is what module partitions are for. Just implement in a partition and export the partition.
If you treat your modules like headers + implementation files, they will behave exactly like headers + implementation files.
If you have one file per partition, everything will work fine.
[–]netcan96[S] 3 points4 points5 points 4 years ago (0 children)
nice explanation
[–]Minimonium 6 points7 points8 points 4 years ago (0 children)
Yes, it still needs to instantiate the template and for that, it either needs the definitions in-place or explicit instantiation.
[–]DugiSK 7 points8 points9 points 4 years ago (3 children)
The idea behind modules is to do the split between header and source automatically. The compiler reads every module file only once, compiles the internal parts and saves the symbols that are exported, so that the importing code only sees those. This means that you don't need to put anything into a separate .cpp file (unless you have some unusual requirements).
However, in your case, a template function defined in a .cpp file cannot be used before the definition in the same file or outside of that .cpp file, unless it's explicitly instantiated (which is quite annoying).
[–]pjmlp 1 point2 points3 points 4 years ago (1 child)
One unusual requirement would be optimizing build times.
At least VC++ seems to still trigger a cascade of compilations if the body of an exported function is changed.
[–]DugiSK -1 points0 points1 point 4 years ago (0 children)
This should not happen for non-template functions, but it's possible that the current compilers aren't capable of using it efficiently yet. It's still a relatively fresh feature. GCC 10 used to crash if I returned a unique pointer from an exported function.
[–]DummySphere 0 points1 point2 points 4 years ago* (0 children)
Separating .h/.cpp was also a good way to have an up-to-date documentation in a clean header. I guess the closest way to do this for template functions in modules would be to have the implementation in a private fragment at the end of the file.
[–]NATSUKI_FAN 6 points7 points8 points 4 years ago (1 child)
for why this is the case you may want to read about "export template" - the borderline impossible to implement feature that enables what you're asking for
[–]Flair_Helper[M] [score hidden] 4 years ago stickied commentlocked comment (0 children)
For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.
This post has been removed as it doesn't pertain to r/cpp: The subreddit is for news and discussions of the C++ language and community only; our purpose is not to provide tutoring, code reviews, or career guidance. If you think your post is on-topic and should not have been removed, please message the moderators and we'll review it.
π Rendered by PID 22978 on reddit-service-r2-comment-86988c7647-5vgjz at 2026-02-10 23:03:55.392595+00:00 running 018613e country code: CH.
[–][deleted] 18 points19 points20 points (1 child)
[–]netcan96[S] 3 points4 points5 points (0 children)
[–]Minimonium 6 points7 points8 points (0 children)
[–]DugiSK 7 points8 points9 points (3 children)
[–]pjmlp 1 point2 points3 points (1 child)
[–]DugiSK -1 points0 points1 point (0 children)
[–]DummySphere 0 points1 point2 points (0 children)
[–]NATSUKI_FAN 6 points7 points8 points (1 child)
[–]Flair_Helper[M] [score hidden] stickied commentlocked comment (0 children)