外部变量的放置

时间:2014-11-11 18:51:21

标签: c++ extern

所以我在我主要的标题列表下面声明了4个外部变量。

我在GUI源代码中的click事件监听器函数中定义了4个变量。编译的代码。

现在重新组织事件监听器函数,我决定将一些代码放入另一个函数中,该函数由事件监听器函数调用。它不会编译,编译器说4个变量是未声明的标识符。

我的印象是全局变量应该在任何地方使用......如果是这样的话,为什么不是这种特殊情况的情况呢?

// 4 extern variables
extern QXlsx::Document BreastCancer;
extern QXlsx::CellRange Range;
extern QXlsx::CellReference BottomLeft;
extern std::vector<patient_data> patients;

int main(int argc, char *argv[])
{

    QApplication a(argc, argv);

    Neutropenia_Main w;
    w.show();

    return a.exec();
}


//declaration
void Neutropenia_Main::on_Load_Patient_Data_clicked()

{

QXlsx::Document BreastCancer("Breast_Cancer.xlsx");
QXlsx::CellRange Range = BreastCancer.dimension();
QXlsx::CellReference BottomLeft = Range.bottomLeft();
int bottomrow = BottomLeft.row();
std::vector<patient_data> patients(bottomrow-1);

extractfromxlsx(bottomrow); // function call

void extractfromxlsx(int bottomrow ){
    patient_data temppatient;
    QVariant tempdata;
    for (int i  = 2; i < bottomrow; i++)
        {
            temppatient.setCaseNumber(BreastCancer.read(i,1));// compiler says BreastCancer is undefined

            tempdata = BreastCancer.read(i,2);
            temppatient.setGender(tempdata.toInt());

0 个答案:

没有答案