我理解 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 中的嵌套类(类型),具有公共(public)访问权限(感谢 PeterWood)
class CppUnit
{
public:
class TestCase
{
// blah blah
};
};
class ComplexNumberTest : public CppUnit::TestCase
{
// also blah
};
关于c++ - C++中的继承语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14333694/