conflict names when we have classes that already do this job?
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
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
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?
Thank you ❤️
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.
std isn't a namespace?
Std is a namespace
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)?
All kinds of situations. I start thinking that we're talking about different things, because namespaces usually contain functions or/and classes.
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 hello(){} void hello(){} That's problem. class Test { public ...void hello() } class Test1 { public ...void hello() } That's not a problem.
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
Why you need two free functions with same signature? Classes and name spaces are different things though.
It just an example, the question isn't if namespaces and classes are same.
Your example is wrong.
Maybe you got it incorrectly?
Обсуждают сегодня