Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
I learning opencv and read a example.
i found the code :
Mat::zeros(200, 320, CV_8UC3)

Mat is a class
i don't understant the meaning of "::".
Help me!
Posted
Comments
Sergey Alexandrovich Kryukov 28-Aug-11 1:25am    
No habit to read language manuals? You could find an answer faster then asking a question.
Also, it's good idea to read all the manual before getting to programming.
--SA

In this example it means qualification of the static function "zeros" uses to show a function of which class it is. As static functions do not use any particular instance of the class and thus cannot access any instance members of the class, they are qualified by the name of the class itself (in some languages like Delphi Pascal they are called "class methods").

The same symbol is also used to qualify any identifier as described in some namespace. This is also a "default namespace" (a namespace when no namespace is specified), then the name can be qualified as "::some_name".

—SA
 
Share this answer
 
v5
Comments
Simon Bang Terkildsen 28-Aug-11 1:40am    
+5 haha, it's usage to refer to a static method totally slipped me. Well hopefully the OP can still use my answer at some point in the future :)
Sergey Alexandrovich Kryukov 28-Aug-11 1:47am    
Thank you, Simon.
Let me see...
--SA
nctit09 28-Aug-11 11:16am    
Thank you...:)
Sergey Alexandrovich Kryukov 28-Aug-11 14:26pm    
You're welcome.
Good luck, call again.
--SA
Edit: See SAKryukov's answer for it's usage in the case you posted. Read the below if you want to know about how else it's used.

:: it is used in combination with namespaces or to solve name conflicts.
Consider this:
C++
class A
{
public:
    void PrintText() { std::cout << "A"; }
};
class B : public A
{
public:
    void PrintText() { std::cout << "B"; }
};

int _tmain(int argc, _TCHAR* argv[])
{
    B b = b;

    b.PrintText();
    b.A::PrintText();

	return 0;
}


First of you see std::cout this tells the compiler to look for cout in the std namespace.

then when we call b.PrintText() "B" is printed but, if we wanted to use A.PrintText we do it like this b.A::PrintText() so we tell the compiler that we want to use A's implementation of PrintText().

A more common problem is when you use multiple inheritance
C++
class Horse
{
public:
    void Eat() { /* Eat code */ }
    void Run();
};
class Bird
{
public:
    void Eat() { /* Eat code */ }
    void Fly();
};
class Pegasus : public Horse, public Bird
{
public:
    void Eat() { Horse::Eat(); }
};

int _tmain(int argc, _TCHAR* argv[])
{
    Pegasus pegasus;

    pegasus.Eat();

	return 0;
}

A horseat leastbird eat different things and in diffPegasusays (atleast looks different). So here we have a pegasus it's a Horse and a Bird (it has four legs, can run anddifferentngs and can fly) but as horses aPegasuss eats in firrent ways we need to decide how the pegasus eats, here we have decided that it eats like a horse void Eat() { Horse::Eat(); }.

I hope it's clear, otherwise tell me and I'll try to clear up any parts that you don't understand.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 28-Aug-11 1:51am    
It would be quite good if you also inferred that OP's case is static function and nothing else because Mat is a class, not a namespace, so this is the only possibility. OP asked about shown fragment of code only; I answered about namespaces only for completeness.
--SA
Ashish Tyagi 40 5-Sep-11 2:19am    
Good Ans +5 form me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900