+ 2

I'm just getting started with C++. What is the difference between header and namespace?

Header, Namespace

18th Dec 2016, 12:00 PM
Doni
Doni - avatar
8 odpowiedzi
+ 7
You can create your own namespace Donna :)
18th Dec 2016, 3:10 PM
Klodian Lula
Klodian Lula - avatar
+ 5
Header files are actual files - stored in the file system, referenced by file name, and #include'd in other files (at least, in C/C++ or other languages using the M4 macro preprocessor). Header files typically group pieces of code that are all interdependent parts of the same specific item together. For instance, a game might have a header file for all of its graphics rendering. Namespaces, on the other hand, are an element of the programming language - they don't exist as a file system object, but rather as a designation within code telling the compiler that certain things are within that namespace. Namespaces typically group interfaces (functions, classes/structs, types) of similar (but not necessarily interdependent) items. For instance, the std namespace in C++ contains all of the Standard Library functions and classes
18th Dec 2016, 12:06 PM
Damian Mathew
Damian Mathew - avatar
+ 4
im using alot of unity. so for example there is an namespace for colorfulFX, what gives me quick access to all the posteffects paremeters. like you could write out std::cout<<... and so on, or just cout<<... same with colorfullfx, i dont want to write colorfillfx everytime, even tho i could
18th Dec 2016, 12:11 PM
Damian Mathew
Damian Mathew - avatar
+ 4
namespace hahaha{ int lalala=5; } int main(){ cout<<hahaha::lalala; }
18th Dec 2016, 12:13 PM
Чистобаев Андрей
Чистобаев Андрей - avatar
+ 4
basicly you could make a namespace when you have alot of things of a kind that you want a quick access for. like for posteffects. But you never need namespaces. they just make your code cleaner
18th Dec 2016, 12:14 PM
Damian Mathew
Damian Mathew - avatar
+ 2
An example of namespace other than std?
18th Dec 2016, 12:09 PM
Doni
Doni - avatar
+ 2
Пространства имён нужны, чтобы предотвратить конфликты имён. Пример: #include <iostream> namespace My{ int var=1; } int main(){ int var=2; std::cout<<var; } Этот код не вызовет ошибок, потому что переменные с одинаковыми именами находятся в разных пространствах имён.
18th Dec 2016, 12:18 PM
Чистобаев Андрей
Чистобаев Андрей - avatar
0
Got some idea about these.. Let me read up and try it out
18th Dec 2016, 3:11 PM
Doni
Doni - avatar