Похожие чаты

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

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

21 ответов

6 просмотров

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

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

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

Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
32
А чем вам питонисты не угодили?😂
.
79
Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
Язык Си можно выучить за день? По книжке ANSI C на 230 страниц
Vincent Vegan
29
Привет, запускаю werf в dind в k8s, получаю ошибку на этапе build/beforeSetup: /.werf/stapel/embedded/bin/bash: /.werf/scripts/5898bdfe5214357d3706b879cc8d3d78460fb379607cbd...
florius0
7
Hello. Could you please help me with finding all coordinates within a radius using a spatial index, given that I have a table with coordinates? SET @lng = 37.57925; SET @lat ...
Rinchin G
2
Всех приветствую. Направьте меня в нужное русло. Постепенно переписываю проект с delphi на lazarus. Приложение - обычный windows/linux клиент для бд firebird. Тут все хорошо. ...
Mishutka
8
Привет всем, подскажите, есть сайт на ево 1.4, надо сделать его мультиязычным, структура документов одинаковой останется, чисто тексты разные, свои тв для каждого языка, поддо...
Oleg
7
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
75
Why ftm dumping??
Sabah Shabu
8
Карта сайта