namespaces - Create my own pre-name like "std" in C++ -
this question has answer here:
- how use namespaces in c++? 15 answers
generally when creates console program writes
#include <iostream> #include <stdlib.h> int main(){ std::cout<<"hello world"<<std::endl; system("pause"); } the std must included call cout , endl statements.
when create library using headers , code in .h , .cpp, , include library, must use name of functions/clases/structs/etc directly. how can make have use pre-word std cout , endl?
it's called namespace.
you can declare own stuff inside namespace this:
namespace mystuff { int foo(); } to define:
int mystuff::foo() { return 42; } to use:
int bar = mystuff::foo(); or, import namespace, can std if don't want fully-qualify everything:
using namespace mystuff; // ... int bar = foo();
Comments
Post a Comment