opencv using C++
using namespace std
what does this actually mean and why do we use it?
using namespace std
what does this actually mean and why do we use it?
std points at the standard c++ namespace on your system containing all basic functionality for c++ functions. if you write it then you are allowed to just use function names and basic c++ types directly.
For example: int c = builtinFunction1(parameter2);
However if you would not use it, you would have to define the same command as
std::int c = std::builtinFunction1(parameter2);
Reason for the existance of namespaces is very simple. C++ does not deny you to redefine existing types or redefine existing functionality. This means that if I would define a namespace TEST, then I could add built-in C++ commands that act totally different as I define it.
The following command would do complete different things if I wanted it to and could be used to divert between my int type and the standard int type.
std::int c = std::builtinFunction1(parameter2); TEST::int c = TEST::builtinFunction1(parameter2);
It would be actually two complete different variables of another type. This is why most OpenCV programs also have the following command: using
namespace cv;
This in turn allows you to use commands like
Mat test = new Mat();
If the command would not have been placed, then the compiler would not recognize the type and would ask you to actually write the following to have working code:
cv::Mat test = new cv::Mat();
Hope this makes sense!
maybe it's easier with an example:
// functions are kept in a separate namespace,
// so they don't involuntarily mix or shadow others:
namespace chai
{
void foo(int);
in bar(float z);
}
// ... other code:
foo(13); // error, foo not found ( missing namespace qualifier )
chai::foo(13); // ok, correct namespace
using chai::foo; // importing only a single symbol
foo(13); // ok found.
bar(13.2); // error, only foo was imported.
using namespace chai; // importing anything from namespace chai
foo(13); // ok found.
bar(13.2); // ok found.
Asked: 2013-02-27 09:23:39 -0600
Seen: 361 times
Last updated: Feb 27 '13
Area of a single pixel object in OpenCV
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
OpenCV DescriptorMatcher matches
Can't compile .cu file when including opencv.hpp
Using OpenCV's stitching module, strange error when compositing images
compile error in opencv2/flann/lsh_table.h when compiling bgslibrary