Lỗi extra qualification the_atm on member operator là lỗi gì năm 2024

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

I am doing the example on dialogs from C++ gui programming with QT 4

I have finddialog.h as [code]

ifndef FINDDIALOG_H

define FINDDIALOG_H

include <QDialog>

class QCheckBox; class QLabel; class QLineEdit; class QPushButton;

class FindDialog : public QDialog { Q_OBJECT

public : FindDialog(QWidget *parent = 0);

signals: void findNext(const QString &str,Qt::CaseSensitivity cs); void findPrevious(const QString &str,Qt::CaseSensitivity cs);

private slots: void findClicked(); void enableFindButton(const QString &text); private: QLabel *label; QLineEdit *lineEdit; QCheckBox *caseCheckBox; QCheckBox *backwardCheckBox; QPushButton *findButton; QPushButton *closeButton;

endif

[/code]

finddialog.cpp [code]

include <QtGui>

include "finddialog.h"

FindDialog::FindDialog(QWidget *parent) : QDialog(parent) { label = new QLabel(tr("Find &what:")); lineEdit = new QLineEdit; label->setBuddy(lineEdit);

 caseCheckBox = new QCheckBox(tr("Match &case"));
 backwardCheckBox = new QCheckBox(tr("Search &backward"));
 findButton = new QPushButton(tr("&Find"));
 findButton->setDefault(true);
 findButton->setEnabled(false);
 closeButton = new QPushButton(tr("Close"));
connect(lineEdit,SIGNAL(textChanged(const QString &)),this,SLOT(enableFindButton(const QString &)));
connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));
connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
QHBoxLayout *topLeftLayout = new QHBoxLayout;

topLeftLayout->addWidget(label); topLeftLayout->addWidget(lineEdit);

QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addLayout(topLeftLayout); leftLayout->addWidget(findButton); leftLayout->addWidget(backwardCheckBox);

QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addLayout(leftLayout); rightLayout->addLayout(rightLayout); rightLayout->addStretch();

QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addLayout(leftLayout); mainLayout->addLayout(rightLayout); setLayout(mainLayout);

setWindowTitle(tr("Find")); setFixedHeight(sizeHint().height()); }

void FindDialog :: findClicked() { QString text = lineEdit->text(); Qt:: CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; if(backwardCheckBox->isChecked()) { emit findPrevious(text,cs); } else{ emit findNext(text,cs); } } void FindDialog :: enableFindButton(const QString &text) { findButton->setEnabled(!text.isEmpty());

} } [/code]

main.cpp [code]

include <QApplication>

include "finddialog.h>

int main(int argc,char *argv[]) { QApplication app(argc,argv); FindDialog *dialog = new FindDialog; dialog->show(); return app.exec(); } [/code]

[code] utkarsh@utkarsh-laptop:~/programming/qt/dialog$ ls dialog.pro finddialog.cpp finddialog.h main.cpp Makefile utkarsh@utkarsh-laptop:~/programming/qt/dialog$ make g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o finddialog.o finddialog.cpp finddialog.cpp:3: error: extra qualification ‘FindDialog::’ on member ‘FindDialog’ finddialog.cpp:3: error: ‘FindDialog::FindDialog(QWidget*)’ cannot be overloaded finddialog.h:14: error: with ‘FindDialog::FindDialog(QWidget*)’ finddialog.cpp:44: error: extra qualification ‘FindDialog::’ on member ‘findClicked’ finddialog.cpp:44: error: ‘void FindDialog::findClicked()’ cannot be overloaded finddialog.h:21: error: with ‘void FindDialog::findClicked()’ finddialog.cpp:56: error: extra qualification ‘FindDialog::’ on member ‘enableFindButton’ finddialog.cpp:56: error: ‘void FindDialog::enableFindButton(const QString&)’ cannot be overloaded finddialog.h:22: error: with ‘void FindDialog::enableFindButton(const QString&)’ finddialog.cpp:60: error: expected unqualified-id at end of input make: *** [finddialog.o] Error 1 utkarsh@utkarsh-laptop:~/programming/qt/dialog$ nano finddialog.cpp utkarsh@utkarsh-laptop:~/programming/qt/dialog$ [/code]

error: Date.cpp:16:12: error: extra qualification ‘Time::’ on member ‘operator+’ [-fpermissive] const Time Time::operator+(const Time &other) ;

What is this? How do I remove this error?

it run fine with Visual Studio

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

# include <iostream> 

# include <iomanip> 
using std::cout; 
using std::setfill; 
using std::setw; 
using std::cin; 
using std::cout; 
using std::endl; 
class Time 
{ 
public: 
Time( int = 0, int = 0 ); 
const Time Time::operator+(const Time &other) ; 
void setTime( int, int); 
void setHour( int ); 
void setMinute( int ); 
int getHour() const; 
int getMinute() const; 
void Time::get( ); 
void Time::display(); 
private: 
int hour;
int minute; 
}; 
Time::Time( int hour, int minute ) 
{ 
setTime( hour, minute); 
} 
void Time::setTime( int hour, int minute ) 
{ 
setHour( hour ); 
setMinute( minute ); 
} 
void Time::get( ) 
{ 
int hour, minute, second; 
cout << "Enter hour : " ; 
cin >> hour; 
cout << endl ;  
cout << "Enter minute : " ; 
cin >> minute; 
cout << endl ;
setTime(hour,minute); 
} 
void Time::setHour( int h ) 
{ 
hour = h; 
} 
void Time::setMinute( int m ) 
{ 
minute = m; 
} 
int Time::getHour ( ) const 
{ 
return hour; 
} 
int Time::getMinute () const 
{ 
return minute; 
} 
void Time::display() 
{ 
cout << setfill( '0' ) << setw( 2 ) << hour << ":" << setw( 2 ) 
<< minute; 
} 
const Time Time::operator+(const Time &other) { 
int hour = (*this).getHour() + other.getHour(); 
int min = (*this).getMinute() + other.getMinute(); 
if ( min > 60 ) 
{ 
min = min - 60; 
hour = hour + 1; 
} 
if ( hour > 24 ) 
{ 
hour = hour - 24; 
} 
return Time( hour, min); 
} 
int main()
{
  Time tm(12,3);
  tm.display();
  int a;
  cin >>a;
  return 0;
}

line 16 - 19 and 83 -85

Last edited on

Learn to indent.

const Time Time::operator+(const Time &other) ; in line 16 is a declaration

1
2
3
class foo{
   //declarations go here
};

as you can see, it is obvious of which class the function is a member of, so there is no need to put `Time::' in the declaration.