sách gpt4 ăn đã đi

c++ - 名为 'exception' 的命名空间导致编译问题

In lại Tác giả: IT Lão Cao 更新时间:2023-10-28 22:09:59 28 4
mua khóa gpt4 giày nike

我有一个名为“异常”的命名空间的问题

让我们考虑以下示例标题:

#include 

namespace exception
{
struct MyException : public std::exception
{};
}


struct AnotherException : public exception::MyException
{
AnotherException() : exception::MyException() { }
};

此 header 无法编译并出现以下错误:

    namespacetest.hpp: In constructor 'AnotherException::AnotherException()': namespacetest.hpp:12:48: error: expected class-name before '(' token namespacetest.hpp:12:48: error: expected '{' before '(' token

There are two solutions for this:

1) qualify namespace with "::" in line 12

AnotherException() : ::exception::MyException() { }

2) 将命名空间重命名为例如“特殊”

命名空间“异常”导致混淆的原因是什么?我知道有一个类 std::exception。这会造成麻烦吗?

câu trả lời hay nhất

I know that there is a class std::ngoại lệ. Does this cause the trouble?

是的。在std::ngoại lệ 中,非限定名称ngoại lệ Đúng注入(inject)的类名。这是继承的,所以在你的类中,一个不合格的 ngoại lệ 指的是那个,而不是你的命名空间。

关于c++ - 名为 'exception' 的命名空间导致编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22627965/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress