| 
 Название: Ошибка компиляции: a function-definition is not allowed here before '{' token;
 Отправлено: ilya2013 от Июня 30, 2013,  06:15
 
 Доброго времени суток. У меня такая проблема main.cpp Код C++ #include "main.h"#include <QtGUI>
 #include <QHBoxLayout>
 #include <QtCore/qcoreevent.h>
 #include <QWidget>
 #include <Calculator.h>
 
 
 int main(int argc, char *argv[])
 {
 
 QApplication a(argc, argv);
 Calculator calkulator;
 calkulator.setWindowTitle("Calkulator");
 calkulator.resize(230,200);
 calkulator.show();
 return calkulator.exec();
 }
 
Calculator.h #ifndef CALCULATOR_H#define CALCULATOR_H
 
 #include <QStack>
 
 #include <QLCDNumber>
 #include <QPushButton>
 
 //==================================
 class Calculator : public QWidget
 {
 Q_OBJECT
 
 private:
 QLCDNumber *lcd;
 QStack<QString> stk;
 QString disp;
 
 public:
 Calculator(QWidget *wgt=0);
 QPushButton* createButton(const QString &str);
 void calculate();
 
 
 public slots:
 void slotButtonCliked();
 
 };
 #endif // CALCULATOR_H
 
Calculator.cpp #include <Calculator.h>#include "main.h"
 #include <QtGUI>
 #include <QBoxLayout>
 #include <QWidget>
 Calculator::Calculator(QWidget *wgt/*=0*/):QWidget(wgt)
 {
 lcd=new QLCDNumber(12);
 lcd->setSegmentStyle(QLCDNumber::Flat);
 lcd->setMinimumSize(150,50);
 
 QChar buttons[4][4]={{'7','8','9','/'},
 {'4','5','6','*'},
 {'1','2','3','-'},
 {'0','.','=','+'},
 };
 
 QGridLayout *lay=new QGridLayout;
 lay->addWidget(lcd,0,0,1,4);
 lay->addWidget(createButton("CE"),1,3);
 for (int i=0; i<4; ++i)
 { for (int j=0; j<4; ++j)
 {
 lay->addWidget(createButton(buttons[i][j]),i+2,j);
 }
 }
 
 
 
 QPushButton* Calculator::createButton(QString &str)
 
 {
 QPushButton *pcmd=new QPushButton(str);
 pcmd->setMinimumSize(40,40);
 connect(pcmd, SIGNAL(clicked()), SLOT(slotButtonCliked()));
 return pcmd;
 }
 
 
 void Calculator::calculate()
 {
 double dOperand = stk.pop().toDouble();
 double dOperand2= stk.pop().toDouble();
 double dResult = 0;
 QString strOper = stk.pop();
 if (strOper=="+")
 {
 dResult=dOperand+dOperand2;
 }
 if (strOper=="-")
 {
 dResult=dOperand-dOperand2;
 }
 if (strOper=="*")
 {
 dResult=dOperand*dOperand2;
 }
 if (strOper=="/")
 {
 dResult=dOperand/dOperand2;
 }
 lcd->display(dResult);
 
 
 }
 setLayout(lay);
 }
 
показывает такие ошибки: a function-definition is not allowed here before '{' token; a function-definition is not allowed here before '{' token; expected '}' at and of input; Прошу помощи... вроде бы не хватает скобки но они все есть
 Название: Re: Ошибка компиляции: a function-definition is not allowed here before '{' token;
 Отправлено: Old от Июня 30, 2013,  07:00
 
 А откуда вы взяли эти файлы?Три последних строки в файле Calculator.cpp относятся к конструктору.
 
 Название: Re: Ошибка компиляции: a function-definition is not allowed here before '{' token;
 Отправлено: ilya2013 от Июня 30, 2013,  07:17
 
 Код взят из книги "Макс Шлее. Qt 4.5. Професcиональное программирование на c++" 
 Название: Re: Ошибка компиляции: a function-definition is not allowed here before '{' token;
 Отправлено: Old от Июня 30, 2013,  07:27
 
 Код взят из книги "Макс Шлее. Qt 4.5. Професcиональное программирование на c++"
 Не внимательно набирали. Я написал выше в чем проблема.
 
 |