ACCESSING STRUCTURE VARIABLES - c++

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!

Related

Incompatible pointer type error while setting directives in Apache server

I am trying to set a directive in Apache server using the example code in the section 'The directive handler function' at
http://httpd.apache.org/docs/2.4/developer/modguide.html.
Here's my code:
static const command_rec example_directives[] =
{
AP_INIT_TAKE1("exampleEnabled", example_set_enabled, NULL, ACCESS_CONF, "Enable or disable mod_privet"),
AP_INIT_TAKE1("examplePath", example_set_path, NULL, ACCESS_CONF, "The path to whatever"),
AP_INIT_TAKE2("exampleAction", example_set_action, NULL, ACCESS_CONF, "Special action value!"),
{ NULL }
};
Handler for directives:
/* Handler for the "exampleEnabled" directive */
const char *example_set_enabled(cmd_parms *cmd, void *cfg, const char *arg)
{
if(!strcasecmp(arg, "on")) config.enabled = 1;
else config.enabled = 0;
return NULL;
}
/* Handler for the "examplePath" directive */
const char *example_set_path(cmd_parms *cmd, void *cfg, char *arg)
{
config.path = arg;
return NULL;
}
/* Handler for the "exampleAction" directive */
/* Let's pretend this one takes one argument (file or db), and a second (deny or allow), */
/* and we store it in a bit-wise manner. */
const char *example_set_action(cmd_parms *cmd, void *cfg, const char *arg1, const char *arg2)
{
if(!strcasecmp(arg1, "file")) config.typeOfAction = 0x01;
else config.typeOfAction = 0x02;
if(!strcasecmp(arg2, "deny")) config.typeOfAction += 0x10;
else config.typeOfAction += 0x20;
return NULL;
}
However, when I try to build, I get the following error:
error: initialization from incompatible pointer type [-Werror]
AP_INIT_TAKE1("examplePath", example_set_path, NULL, ACCESS_CONF, "The path to whatever")
Am I missing out on something?
Thanks
Third parameter of example_set_path should be const char *arg
#define AP_INIT_TAKE1 ( directive,
func,
mconfig,
where,
help ) { directive, { .take1=func }, mconfig, where, TAKE1, help }
func is defined as...
const char *(* take1 )(cmd_parms *parms, void *mconfig, const char *w)

error: C2059: syntax error : '{'

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.

C++ getting error C2440

Hello I'm using Visual Studio c++ 2010
I'm having a problem with this code ( it's taken from C language code ) :
MEMBLOCK* create_memblock (HANDLE hProc, MEMORY_BASIC_INFORMATION *meminfo)
{
MEMBLOCK *mb = malloc(sizeof(MEMBLOCK));
if (mb)
{
mb->hProc = hProc;
mb->addr = meminfo->BaseAddress;
mb->size = meminfo->RegionSize;
mb->buffer = malloc(meminfo->RegionSize);
mb->next = NULL;
}
return mb;
}
I'm having these errors :
error C2440: 'initializing' : cannot convert from 'void *' to 'MEMBLOCK *'
error C2440: '=' : cannot convert from 'PVOID' to 'unsigned char *'
error C2440: '=' : cannot convert from 'void *' to 'unsigned char *'
I'm kinda newbie. Can you please provide a converted code for this that actually works with c++.
Thank you
Since you're programming in C++, you should not use the old C function malloc. Instead I would recommend that you use the C++ new construct:
MEMBLOCK *mb = new MEMBLOCK;
In C++ You may not assign a pointer of type void * to a pointer of some other type. So for example instead of writing
MEMBLOCK *mb = malloc(sizeof(MEMBLOCK));
You have to write
MEMBLOCK *mb = ( MEMBLOCK * )malloc(sizeof(MEMBLOCK));
Also you have to change other statements where there is the same problem. It seems these statements are
mb->addr = ( unsigned char * )meminfo->BaseAddress;
mb->buffer = ( unsigned char * )malloc(meminfo->RegionSize);
It is a good example of that you always should use an explicit casting even in C. That makes the code more safe and clear.
malloc() returns void*, and C++ does not automatically cast void* to a different pointer type. So you have to cast the return value:
MEMBLOCK *mb = (MEMBLOCK*) malloc(sizeof(MEMBLOCK));
Try:
MEMBLOCK* create_memblock (HANDLE hProc, MEMORY_BASIC_INFORMATION *meminfo)
{
MEMBLOCK *mb = (MEMBLOCK*)malloc(sizeof(MEMBLOCK));
if (mb)
{
mb->hProc = hProc;
mb->addr = meminfo->BaseAddress;
mb->size = meminfo->RegionSize;
mb->buffer = malloc(meminfo->RegionSize);
mb->next = NULL;
}
return mb;
}

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 }
};

Resolve c++ pointer-to-member error in VS 2003

I have a c++ program that I'm trying to port from VS98 to VS2003 (incremental steps). One error that occurs throughout is "Error 2275"
For instance: k:\RR\chart\chartdlg.cpp(2025): error C2475: 'CRrDoc::cFldFilter' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name
The offending code is shown below:
void CDataPage::OnBtnLabelField()
{
FLDID fid ;
LPMFFIELD f ;
CRrApp *pApp = (CRrApp *)AfxGetApp();
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
CRrDoc *pDoc = (CRrDoc *)pFrame->GetActiveDocument();
CSelectFieldDlg dlg;
//**************************************************
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter;
//dlg.ck = CRrDoc->*zcFldFilter;
//**************************************************
dlg.ck = pDoc->cFldFilter ;
dlg.TitleTextID = IDS_2676;
fid = (FLDID)dlg.DoModal();
if (fid != NOID)
{
f = pDoc->m_pComposite->mfbyndx(fid);
// find index
int i, iCount;
iCount = m_lboxLabel.GetCount();
for (i = 0; i < iCount; i++)
{
if(fid == m_lboxLabel.GetItemData(i))
{
m_lboxLabel.SetCurSel(i);
OnSelchangeComboLabel();
}
}
}
}
I tried handling it according to a Microsoft page: But that just generated a set of other problems (the commented code between the asterisks). Note that I also commented out the following line:
dlg.ck = pDoc->cFldFilter
Unfortunately, this leads to a new error: k:\RR\chart\chartdlg.cpp(2022): error C2440: 'initializing' : cannot convert from 'BOOL (__cdecl )(LPMFFIELD)' to 'BOOL CRrDoc:: '
The definition in the .H file looks like:
public:
static BOOL cFldFilter(LPMFFIELD f);
Any ideas how to handle the pointer-to-member issue?
since you have:
static BOOL CRrDoc::cFldFilter(LPMFFIELD f);
its type is not a member variable but a function:
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter; // doesn't work
BOOL (*zcFldFilter)(LPMFFIELD) = &CRrDoc::cFldFilter; // works
Since dlg.ck is of a correct type, you should do
dlg.ck = &CRrDoc::cFldFilter;