Похожие чаты

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

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

21 ответов

39 просмотров

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

Платиновый Хамелеон
C++'s OO is weird

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

Дизельный Бобр
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

Безоблачный-Батон Автор вопроса
Дизельный Бобр
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?

Безоблачный Батон
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.

Безоблачный-Батон Автор вопроса
Дизельный Бобр
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)?

Безоблачный Батон
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.

Безоблачный-Батон Автор вопроса
Дизельный Бобр
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" ?

Безоблачный-Батон Автор вопроса
Лукавый Торт
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 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 hello(){} void hello(){} That's problem. cla...

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

Безоблачный-Батон Автор вопроса
Корабельное Плато
Why you need two free functions with same signatur...

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

Безоблачный-Батон Автор вопроса

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Мелодичный Сырник
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Фетровый Лингвист
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Настойчивый Кварк
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...
Льдистая Лужица
2
30500 за редактор? )
Замшевый Алхимик
47
а через ESC-код ?
Виноградная Притча
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...
Звенящий Циферблат
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Туманный Ларец
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Длинный Минерал
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Тягучая Ракушка
11
Карта сайта