c++中的继承语法
Inheritance syntax in C++
我理解了c++中继承的语法:
class DerivedClassName : public BaseClassName {}
然而,在一个程序中,我发现了这样一个字符串:
class ComplexNumberTest : public CppUnit::TestCase {
,我不明白它是什么意思。很明显,ComplexNumberTest
是CppUnit
的子类,但TestCase
是什么呢?
我认为CppUnit::TestCase
是指CppUnit
类的TestCase
方法,但DerivedClassName
应该是一个方法的子类?
CppUnit是命名空间,ComplexNumberTest是从CppUnit命名空间中派生出来的TestCase类。
在你的代码中,你有这样的TestCase:
namespace CppUnit
{
class TestCase
{
// blah blah
};
}
或者TestCase可以是CppUnit内部具有公共访问权限的嵌套类(类型)(感谢PeterWood)
class CppUnit
{
public:
class TestCase
{
// blah blah
};
};
class ComplexNumberTest : public CppUnit::TestCase
{
// also blah
};
CppUnit是一个命名空间,或者TestCase是CppUnit中的一个嵌套类。
如果是命名空间:您可以通过使用名称空间:
来摆脱这种语法。using namespace CppUnit;
class ComplexNumberTest : public TestCase {
Although, you don't usually want to put using namespace in a header file.
-感谢评论@PeterWood
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 继承函数的重载解析
- 助记符和指向成员语法的指针
- 关于异常继承中的语法的问题
- C++状态机,继承了具有语法不正确的成员值的类
- 使用继承的 C++ 语法
- 正确的语法,用于在C 中继承,并具有初始化列表和内存分配
- 派生模板类和继承成员变量的语法谜题
- 用于在多重继承中覆盖函数的语法
- 继承自 std::函数、语法和用法
- 使用 Qt5 新连接语法与继承
- 将boost::spirit符号表作为继承属性传递到语法中
- 继承中的语法错误
- 模板构造函数继承的标准符合语法是什么
- c++继承语法
- 继承……c++语法
- 试图为继承类的子类编写构造函数,猜测语法,期望的主表达式错误
- 具有合成和继承属性的深度递归qi语法(解析器)
- 从std::set或std::map继承初始化语法
- c++中的继承语法