2013-04-16 72 views
2

我见过在许多项目中,一些程序员在他们的代码中使用了//! [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 doc评论。 – Rapptz

+0

你可以举一个你已经看到完成的项目的例子吗? –

+0

这就是编码的力量。 –

回答

6

我只是猜测,因为你不显示更完整的代码(或在这种情况下,更完整的注释)。

Doxygen是一个文档生成器,用于解析代码声明和特定格式的注释。如果您阅读this part of the manual,您将看到它将//!识别为包含文档的特殊注释。 Doxygen支持markdown,它们在方括号内有链接。

所以这和实际的代码没什么关系,除了帮助记录它。这当然不是编译器会尝试为其生成代码的声明。

+2

您可以添加任何C(99或更高版本)或C++编译器将*始终*识别“//”作为注释,直到行结束为止,没有例外。 – dascandy

+0

我认为上面的snipe代码明确了我的意图。 – user1695063

+0

@ user1695063看起来像标记链接,就像在SO上格式化链接时可以使用的一样。 –

1

这些仅仅是评论。它们在C或C++中没有特殊含义。它们在其他一些情况下可能有一些特殊含义,或者它们可能仅仅是该项目的评论惯例。