这个语句 //! [number] 是什么意思?

3

我在很多项目中看到一些程序员在他们的代码中使用//! [1]//! [2],...,//! [n],但我不知道这意味着什么。

如果有人指出这些注释的用途,我将不胜感激。 这是一段样例代码:

BlockingClient::BlockingClient(QWidget *parent)
    : QWidget(parent)
{
    hostLabel = new QLabel(tr("&Server name:"));
    portLabel = new QLabel(tr("S&erver port:"));


    QString ipAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // use the first non-localhost IPv4 address
    for (int i = 0; i < ipAddressesList.size(); ++i) {
    }
    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

    //...
    connect(hostLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(enableGetFortuneButton()));
    connect(portLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(enableGetFortuneButton()));
//! [0]
    connect(&thread, SIGNAL(newFortune(QString)),
            this, SLOT(showFortune(QString)));
//! [0] //! [1]
    connect(&thread, SIGNAL(error(int,QString)),
            this, SLOT(displayError(int,QString)));
//! [1]

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(hostLabel, 0, 0);
    setLayout(mainLayout);

    setWindowTitle(tr("Blocking Fortune Client"));
    portLineEdit->setFocus();
}

//! [2]
void BlockingClient::requestNewFortune()
{

    getFortuneButton->setEnabled(false);
    thread.requestNewFortune(hostLineEdit->text(),
                             portLineEdit->text().toInt());
}
//! [2]

//! [3]
void BlockingClient::showFortune(const QString &nextFortune)
{
    if (nextFortune == currentFortune) {
        requestNewFortune();
        return;
    }
//! [3]

//! [4]
    currentFortune = nextFortune;
    statusLabel->setText(currentFortune);
    getFortuneButton->setEnabled(true);
}
//! [4]

6
看起来是某种Doxygen文档注释。 - Rapptz
你能举一个你见过这样做的项目的例子吗? - Kevin Brydon
编程三位一体。 - Luchian Grigore
当我想知道我的同事写了什么代码时,我会询问他们。你有没有问过你的同事为什么把那段代码放在那里? - default
2个回答

8
我猜测你没有展示更完整的代码(或在这种情况下更完整的注释),因此需要对此进行解释。 Doxygen 是一个文档生成器,可以解析特定格式的代码声明和注释。如果您阅读 该手册的这一部分 ,则会发现它将//!识别为包含文档的特殊注释。Doxygen支持 markdown,其中方括号内有链接。
因此,除了帮助记录代码外,这与实际代码无关。当然,这也不是编译器尝试生成代码的语句。

2
您可以添加任何 C (99 及以上版本) 或 C++ 编译器将始终将 "//" 识别为注释,直到行末,没有例外。 - dascandy
看起来像标记链接,就像在 SO 上格式化链接时使用的方式一样。 - Some programmer dude

1

这些只是注释,在C或C++中没有特殊意义。它们可能在其他上下文中具有特殊含义,或者仅仅是该项目的注释约定。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接