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

I would like to run an application in qt creator. But when i click on build, it showing error in carddetect.cpp
The error occurs here: void CardDetect::aamvaIssuerList()
But I can't find out what that error is.
124: error: C2059: syntax error : '{'
124: error: C2143: syntax error : missing ';' before '{'
124: error: C2143: syntax error : missing ';' before '}'
This is my code:
#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" };
}
and carddetect.h is
#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
That code working #keltar
but now in this function
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
}
It showing error
error: C2512: 'issuer' : no appropriate default constructor available
error: C2512: 'issuer::issuer' : no appropriate default constructor available
in struct issuer issuerInfo;

Since you cannot use compound literals, here is an example of how it could be done:
Add constructor to your structure:
struct issuer {
issuer(const char *nm, const char *abbr, const char *fmt) : name(nm),
abbreviation(abbr), format(fmt) {}
QString name;
QString abbreviation;
QString format;
};
And change your function to:
void CardDetect::aamvaIssuerList(){
issuerList [ "636026" ] = issuer("Arizona", "AZ", "L");
// same for the rest of the lines
}
There are other ways to do the same, of course.

Related

qt creator issue when include std string library

I have this function. I created it with libxml2 and std::string library.
#ifndef KNIHOVNA_H
#define KNIHOVNA_H
#include <string>
#include <libxml/tree.h>
std::string hledaniString(int index,xmlDocPtr sharedString)
{
std::string Istring;
xmlAttrPtr attr;
xmlChar *attrValue;
xmlNodePtr nodeLevel1 = sharedString->children;
int maxValue;
int aIndex;
attr = xmlHasProp(nodeLevel1, (const xmlChar*)"uniqueCount");
if (attr !=NULL)
{
attrValue = xmlGetProp(nodeLevel1, (xmlChar *)"uniqueCount");
}
else return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
nodeLevel1 = nodeLevel1->children;
maxValue = atoi((const char *) attrValue);
xmlFree(attrValue);
if (maxValue<=index) return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
for (aIndex = 0;aIndex < index; aIndex++ )
{
nodeLevel1 = nodeLevel1->next;
}
nodeLevel1 = nodeLevel1->children;
attrValue = xmlNodeGetContent(nodeLevel1);
xmlFree(attrValue);
attrValue = xmlNodeGetContent(nodeLevel1);
Istring = (char *) attrValue;
xmlFree(attrValue);
return Istring;
#endif // KNIHOVNA_H
I use it in Code Block project where is everything ok and in qt creator project where I get these errors:
/usr/include/c++/4.8/string:38: In file included from /usr/include/c++/4.8/string:38:0,
/usr/include/c++/4.8/bits/stl_relops.h:-1: In function 'std::string getString(int, xmlDocPtr)':
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected '=' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected identifier before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected primary-expression before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/home/daffy/qt projektz/revize/main.cpp:15: error: expected '}' at end of input
Could someone help me please ?

Syntax error : missing '{ ' before '.'

I have an AVOption structure:
static const AVOption options[] = {
COMMON_OPTIONS // error here
{ NULL }
};
and COMMON_OPTIONS is defined as:
#define COMMON_OPTIONS \
{ "interp", "select interpolation mode", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERPOLATE_TETRAHEDRAL}, 0, NB_INTERP_MODE-1, FLAGS, "interp_mode" }, \
{NULL}
I am getting an error:
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(98): error C2143: syntax error : missing '}' before '.'
Your COMMON_OPTIONS macro has already the { NULL } and does not ends with a ,, so:
static const AVOption options[] = {
COMMON_OPTIONS
};
will solve your problem.
Past answer before the edit:
Even if we don't know what does COMMON_OPTIONS expand to, I guess that you just miss the comma after it:
static const AVOption options[] = {
COMMON_OPTIONS,
// ^
{ NULL }
};

ACCESSING STRUCTURE VARIABLES

I have an structure AVFilter,
AVFilter avfilter_vsrc_color = {
.name = "color", // error here
.description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
.priv_class = &color_class,
.priv_size = sizeof(TestSourceContext),
.init = color_init,
.uninit = uninit,
.query_formats = color_query_formats,
.inputs = NULL,
.outputs = color_outputs,
.process_command = color_process_command,
};
and AVFilter is defined as,
typedef struct AVFilter {
const char *name;
const char *description;
const AVFilterPad *inputs;
const AVFilterPad *outputs;
const AVClass *priv_class;
int flags;
int (*init)(AVFilterContext *ctx);
int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
void (*uninit)(AVFilterContext *ctx);
int (*query_formats)(AVFilterContext *);
int priv_size; ///< size of private data to allocate for the filter
struct AVFilter *next;
int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
int (*init_opaque)(AVFilterContext *ctx, void *opaque);
} AVFilter;
I m getting error like ,
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(268): error C2143: syntax error : missing '}' before '.'
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(268): error C2143: syntax error : missing ';' before '.'
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(268): error C2059: syntax error : '.'
Please let us know which line is 268!
Please try removing the comma for
.process_command = color_process_command,
and try compiling it again. if you can give us more details like which line is 268 it will be possible to find the reason!

error C2440: 'type cast' : cannot convert from 'overloaded-function' to

I have a piece of code which worked fine on a previous projet. A part of it was even copied from a working demo project and I don't know how I can have this error on a new project now.
When compiling, I have the following error :
1>d:\visual studio 2012\netsdk_poc\mfc_netsdk2\mfc_netsdk2\netsdkfunctions.cpp(33): error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'fDisConnect'
The code :
class CNetSDKFunctions{
void __stdcall DisConnectBackCallFunc(LONG lLoginID, char *pchDVRIP,
LONG nDVRPort, DWORD dwUser)
{
CNetSDKFunctions* pThis = (CNetSDKFunctions*)dwUser;
if (pThis == NULL)
{
ASSERT( FALSE );
return ;
}
//pThis->ReConnect(lLoginID, pchDVRIP, nDVRPort);
}
BOOL CNetSDKFunctions::InitSDK()
{
long m_PlayerHandle;
H264_DVR_GetLastError();
H264_DVR_Init(NULL, 0);
//Here it is :
BOOL logResult = H264_DVR_Init( (fDisConnect) DisConnectBackCallFunc, (DWORD) this );
....
}
And fDisConnect definition :
typedef void (CALL_METHOD *fDisConnect)(long lLoginID, char *pchDVRIP, long nDVRPort, unsigned long dwUser);

error C2065: 'CR_HASTE_MELEE' : undeclared identifier

I am having problems referencing an Enumeration from one header file to another.
I have "Unit.h" which contains:
enum CombatRating
{
CR_HASTE_MELEE = 17,
CR_HASTE_RANGED = 18,
CR_HASTE_SPELL = 19,
};
Then "Object.h" which contains:
void ApplyPercentModFloatValue(uint16 index, float val, bool apply)
{
float value = GetFloatValue(index);
ApplyPercentModFloatVar(value, val, apply);
if (apply && index == CR_HASTE_MELEE && value > 130.86f)
value = 130.86f;
SetFloatValue(index, value);
}
When I build my project, I receive "error C2065: 'CR_HASTE_MELEE' : undeclared identifier". I tried an include for "Unit.h" within "Object.h" but that gives me loads of errors too.
Is there any way to reference the Enum across header files so that a percentage can be applied to "CR_HASTE_MELEE"?
Thanks