Похожие чаты

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

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

21 ответов

12 просмотров

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- Автор вопроса

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
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
Карта сайта