问题描述
我学习opencv并阅读了示例.
我找到了代码:
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!
推荐答案
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;
}
首先,您会看到std::cout
这告诉编译器在std名称空间中查找cout.
那么当我们调用b.PrintText()
时,会打印出"B",但是,如果我们想使用A.PrintText
,我们会像这样b.A::PrintText()
那样进行操作,因此我们告诉编译器我们要使用A
的PrintText()
实现>.
一个更常见的问题是当您使用多重继承时
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
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;
}
至少马的鸟在diffPegasusays中吃不同的东西(看上去至少是不同的).因此,这里有一个飞马座,它是马和鸟"(它有四只腿,可以奔跑和与众不同,可以飞翔),但是当飞马座以不同方式进食时,我们需要确定飞马座的饮食方式,在这里我们已经决定了它吃得像马void Eat() { Horse::Eat(); }
.
我希望一切都清楚了,否则请告诉我,我将尝试清理您不理解的所有部分.
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.
这篇关于什么是符号"::"? vs c ++是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!