Похожие чаты

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

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

12 ответов

3 просмотра

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

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

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

Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
For all those that keep asking why no pump? why this ? and why that...? Please close ur ewt chart and open 2 others - TOTAL (total mc) and BTC.D (btc dominance). Maybe BTC a...
Inn3r_G
19
"Since pnut can flip FTM easily, I'm swapping my FTM to pnut and hoping for a easy x5-x10" Perfect recipe for disaster. NFA but chances are, you'll end up as exit liquidity ...
C. A.
7
AMD status update? No longer in the plan but something might be around the corner later on Chinese partner? No longer in the plan. This market does not seem to be the top ...
Ben
6
Добрый день, подскажите, пожалуйста, по проблеме. Сегодня на работе утром обнаружилось что по рдп подключиться не получается к серверу 2022. В серверную зашел - на системно...
srv
19
Чтобы перехватить все нажимания буков на форме, надо хук ставить? Пробовал на форме ОнКейДаун, оно ловит клаву если фокус не на компоненте с вводом текста
Serjone
15
Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
лучше скажите, причём тут паскаль?
Alexey Kulakov
36
Всем привет! вывожу на общей стр дочерние ресурсыв каждом ресурсе галерея, и первая фотка должна выводиться на общей [!DocLister? &prepare=photo !]
Alekso
12
А можно вопрос? Мне сегодня сказали что у меня функция (которая просто заполняет массив значениями) не правильная void Full(double * arr, int n) { for (int i = 0; i < n; i...
† C E †
7
Карта сайта