+ 2
I'm just getting started with C++. What is the difference between header and namespace?
Header, Namespace
8 odpowiedzi
+ 7
You can create your own namespace Donna :)
+ 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
+ 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
+ 4
namespace hahaha{
int lalala=5;
}
int main(){
cout<<hahaha::lalala;
}
+ 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
+ 2
An example of namespace other than std?
+ 2
Пространства имён нужны, чтобы предотвратить конфликты имён. Пример:
#include <iostream>
namespace My{
int var=1;
}
int main(){
int var=2;
std::cout<<var;
}
Этот код не вызовет ошибок, потому что переменные с одинаковыми именами находятся в разных пространствах имён.
0
Got some idea about these.. Let me read up and try it out