Ask Your Question
0

opencv using C++

asked 2013-02-27 09:23:39 -0600

chaitanya gravatar image

using namespace std

what does this actually mean and why do we use it?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-27 11:44:36 -0600

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!

edit flag offensive delete link more
1

answered 2013-02-27 09:34:59 -0600

berak gravatar image

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.
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-27 09:23:39 -0600

Seen: 316 times

Last updated: Feb 27 '13