1
我想在qt創建者中運行應用程序。但是,當我在構建點擊,它顯示carddetect.cpp錯誤:C2059:語法錯誤:'{'
錯誤錯誤發生在這裏:void CardDetect::aamvaIssuerList()
但我不能找出是什麼錯誤。
124: error: C2059: syntax error : '{'
124: error: C2143: syntax error : missing ';' before '{'
124: error: C2143: syntax error : missing ';' before '}'
這是我的代碼:
#include "carddetect.h"
#include <QDebug>
void CardDetect::aamvaIssuerList(){
issuerList [ "636026" ] = (struct issuer) {"Arizona", "AZ", "L"};
issuerList [ "0636021"] = (struct issuer) { "Arkansas", "AR", "" };
issuerList [ "636014" ] = (struct issuer) { "California", "CA", "L" };
issuerList [ "636020" ] = (struct issuer) { "Colorado", "CO", "NN-NNN-NNNN" };
issuerList [ "636010" ] = (struct issuer) { "Florida", "FL", "LNNN-NNN-NN-NNN-N" };
issuerList [ "636018" ] = (struct issuer) { "Iowa", "IA", "NNNLLNNNN" };
}
和carddetect.h是
#ifndef CARDDETECT_H
#define CARDDETECT_H
#include <QMap>
#include "magcard.h"
struct issuer {
QString name;
QString abbreviation;
QString format;
};
class CardDetect {
public:
CardDetect(MagCard *_card = 0);
void setCard(MagCard *_card);
private:
MagCard *card;
void processCard();
void luhnCheck();
void creditCardCheck();
void aamvaCardCheck(QString expDate);
void aamvaIssuerList();
QMap<QString,struct issuer> issuerList;
};
#endif // CARDDETECT_H
該代碼@keltar
但是現在在這個函數工作
void CardDetect::aamvaCardCheck(QString expDate) {
if(card->encoding == IATA)
return; //we're only going to support ABA for now
struct issuer issuerInfo;
QString iin = card->accountNumber.left(6);
issuerInfo = issuerList.value(iin);
if(issuerInfo.name.isEmpty()) {
iin = card->accountNumber.mid(1, 6);
issuerInfo = issuerList.value(iin);
if(issuerInfo.name.isEmpty())
return; // this is not a known AAMVA card, abort
}
它表示結構發行者issuerInfo錯誤
error: C2512: 'issuer' : no appropriate default constructor available
error: C2512: 'issuer::issuer' : no appropriate default constructor available
;
用** C和C++標記這個問題是沒有意義的,因爲它意味着C和C++中的不同。在C(99)中,這是有效的代碼,在C++中,它不是。那麼,您使用的是哪種語言? – 2014-11-25 09:11:54
@TheParamagneticCroissant你似乎很困惑。這顯然是C++而不是C. – 2014-11-25 09:16:50
您正在使用的構造('(type){initialiser}')是複合文字;它是C11,或任何GNU C/C++,但據我所知,它不是標準的C++,MSVC不支持它。重寫你的代碼。 – keltar 2014-11-25 09:21:43