Похожие чаты

Hello I have a question Why do we need namespace to avoid

conflict names when we have classes that already do this job?

21 ответов

11 просмотров

Namespaces are usually used for free functions that are not bound to any specific class. You can replace a namespace with a class with public static functions and it will work, but this class then can be instantiated which is strange. Also this may be unexpected for a reader of the code why class was used there instead of a namespace. I would say that namespace is a different concept, it doesn't technically implies more than adding name prefixes to resolve name conflicts. Where as class is a higher-level and more complex concept that should be used for solving more complex problems.

https://del.dog/thycenangy.go

Nader Jafari
C++'s OO is weird

Namespaces are not part of OO stuff as far as I know

Pavel
Namespaces are not part of OO stuff as far as I kn...

Well yes but actually no namespaces are usually used in Object oriented languages C++ is influenced by Ada and Smalltalk and got this features from these languages

Void- Автор вопроса
Pavel
Namespaces are usually used for free functions tha...

Thanks you very much for you answer. Then, why do we have std namespace for example that it contains as far as i know - classes?

Void- Автор вопроса
Void
Thanks you very much for you answer. Then, why do ...

You can think of it as of name prefixes (that not needed when you work inside the namespace). E.g. instead of std_string we have std::string. But std is not a class.

Void- Автор вопроса
Void
std isn't a namespace?

I mean that it's no more than a namespace

Void- Автор вопроса
Pavel
I mean that it's no more than a namespace

Is there a situations when we want to use namespace that contains classes (n maybe regular functions too)?

Void
Is there a situations when we want to use namespac...

All kinds of situations. I start thinking that we're talking about different things, because namespaces usually contain functions or/and classes.

Void- Автор вопроса
Pavel
All kinds of situations. I start thinking that we'...

We are talking on same things. I'm just exploring all the options. thanks for your answers.

just for clarification what do you mean by stating "classes avoid name conflicts" ?

Void- Автор вопроса
Sunbro
just for clarification what do you mean by stating...

void hello(){} void hello(){} That's problem. class Test { public ...void hello() } class Test1 { public ...void hello() } That's not a problem.

Void
void hello(){} void hello(){} That's problem. cla...

you should read again about oop and what classes are used for. because the situation you are describing will never occur as a problem. this situation as a problem can only occur in functional programming where you are using namespaces to avoid naming conflicts

Void
void hello(){} void hello(){} That's problem. cla...

Why you need two free functions with same signature? Classes and name spaces are different things though.

Void- Автор вопроса
Пользователь 61653
Why you need two free functions with same signatur...

It just an example, the question isn't if namespaces and classes are same.

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

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

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

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
Добрый вечер. Есть вопрос, а может и предложение. Был у меня диалог в другой группе о делфи и я задался вопросом: "А нельзя ли в делфи цвет //коментария и {комментария} сде...
Kraszx
24
How about the project bro Likes the community not that active ?
🅿️abby_FX
19
Всем привет! Подскажи, пожалуйста, как передать в TComboBox сразу значение и id записи. На Delphi я делал так: ComboBox1.Items.AddObject('Какое-то значение', Pointer(id запис...
Евгений
13
Мдя, прикол, боевая сборка запускается (именно под отладчиком) после F9 примерно полторы минуты (97 секунд если быть точным). Начал копать - проблема детектится сразу - зависа...
Александр (Rouse_) Багель
38
How are we going bro about the Raids ??
🅿️abby_FX
13
Россия стала ввозить сливочное масло из ОАЭ. Просто ради любопытства взглянул на статистику и впечатлился. У арабов среднестатистическая корова дает около 42 литров молока в д...
Foxcool
2
Здравствуйте, вопрос по структурам данных. Были у вас случаи, когда пришлось писать деревья или двунаправленные списки?
/ /
50
Товарищи, кто работа с iphelper? Или может я в самой логике ошибки фигачу, не пойму.... var ifTable : PMIB_IFTABLE; size, corSize: DWORD; Buffer ...
Warfarellen
4
я так понимаю, я так подозреваю, что создание такого плагина для человека, кто умеет писать плагины для делфи потребует минут 5-10 времени. но это мое подозрение. хотелось бы ...
Kraszx
7
Карта сайта