gpt4 book ai didi

c++ - 错误 : C2059: syntax error : '{'

转载 作者:太空宇宙 更新时间:2023-11-04 11:24:38 25 4
gpt4 key购买 nike

我想在 qt creator 中运行一个应用程序。但是当我点击构建时,它在 carddetect.cpp 中显示错误

错误发生在这里: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
}

显示错误

error: C2512: 'issuer' : no appropriate default constructor available
error: C2512: 'issuer::issuer' : no appropriate default constructor available

在结构发行人发行人信息中;

最佳答案

由于您不能使用复合字面量,下面是一个如何实现的示例:

将构造函数添加到您的结构中:

struct issuer {
issuer(const char *nm, const char *abbr, const char *fmt) : name(nm),
abbreviation(abbr), format(fmt) {}

QString name;
QString abbreviation;
QString format;
};

并将您的功能更改为:

void CardDetect::aamvaIssuerList(){
issuerList [ "636026" ] = issuer("Arizona", "AZ", "L");
// same for the rest of the lines
}

当然,还有其他方法可以做到这一点。

关于c++ - 错误 : C2059: syntax error : '{' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27122529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com