Похожие чаты

Hey Why do I need headers files in c++ code when

creating non library program? does it possible to import namespace without headers?

12 ответов

21 просмотр

wdym?

Jacob- Автор вопроса

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)

Jacob
main.cpp int main() { foo::hello(); } foo.cpp ...

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.

Jacob- Автор вопроса
Pavel
You can forward-declare in your cpp file, basicall...

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

Jacob
I'm coming from rust and there I don't need header...

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.

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

Pavel
Don't know about that, every compilation would rec...

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

Thomas
Molly Rocket (Casey) does single translation unit ...

Interesting, so it's a gigantic unity bucket then. Didn't think that would ever work

Pavel
Interesting, so it's a gigantic unity bucket then....

Well no, more like one unity per project I bet, and something like <10 projects

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта