creating non library program? does it possible to import namespace without headers?
wdym?
main.cpp int main() { foo::hello(); } foo.cpp namespace foo { void hello() { } } Currently I must create foo.h and include it to use foo::hello in main.cpp (VSCode, Clangd, Clang)
You can forward-declare in your cpp file, basically add the content of your *.h file to the target cpp. However it would result in code duplication as you would need to copy this code around everywhere, and if you need to change something, change it everywhere. Basically header files are the solution to this problem of duplication.
I'm coming from rust and there I don't need headers I just import the namespace / module I feel like I'm writing headers in c++ for no reason it's just CLI app it would be cool if it's generated automatically
If you are writing something small that doesn't require fast compile times, you can move definitions of your functions to the header, just make sure you mark everything global (functions and variables) as inline. Though if it grows big, that could hit compilation and linking times hard.
You don't need headers really
Don't know about that, every compilation would recompile everything in a single thread, since there's only one translation unit. There are much smaller projects that can compile for minutes even without this
Molly Rocket (Casey) does single translation unit for most of his projects, and he claims he can build all the code they have in like 10 seconds (>500kLoC), across all projects Zig is entirely single translation unit, including libraries, and is still mostly parallel
Interesting, so it's a gigantic unity bucket then. Didn't think that would ever work
Well no, more like one unity per project I bet, and something like <10 projects
Обсуждают сегодня